Open iOSDevil opened 11 years ago
Currently setting a titleView is only supported before pushing the new layer. Nevertheless, that's a bug...
So, as a workaround: Set the titleBar before pushing, e.g.
[self.layeredNavigationController pushViewController:svc
inFrontOf:self
maximumWidth:YES
animated:YES
configuration:^(FRLayeredNavigationItem *item) {
UISegmentedControl *segControl = [[UISegmentedControl alloc]
initWithItems:[NSArray
arrayWithObjects:@"foo", @"bar", @"buz", nil]];
item.titleView = segControl;
}];
Thanks, that works fine
On 1 Jan 2013, at 22:25, Johannes Weiß notifications@github.com wrote:
Currently setting a titleView is only supported before pushing the new layer. Nevertheless, that's a bug...
So, as a workaround: Set the titleBar before pushing, e.g.
[self.layeredNavigationController pushViewController:svc inFrontOf:self maximumWidth:YES animated:YES configuration:^(FRLayeredNavigationItem *item) { UISegmentedControl *segControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"foo", @"bar", @"buz", nil]]; item.titleView = segControl; }];
— Reply to this email directly or view it on GitHub.
+1
FYI: I hacked it for now by adding this category on FRLayerController:
#import <FRLayeredNavigationController/FRLayeredNavigationItem+Protected.h>
#import <FRLayeredNavigationController/FRLayerController.h>
#import <FRLayeredNavigationController/FRLayerChromeView.h>
@implementation FRLayerController (Hack)
- (void)hackSetTitleView:(UIView *)titleView;
{
if (titleView == nil) {
UILabel *titleLabel = [[UILabel alloc] init];
const NSDictionary *titleTextAttrs = [[FRNavigationBar appearance] titleTextAttributes];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.text = self.layeredNavigationItem.title;
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.font = [titleTextAttrs objectForKey:UITextAttributeFont];
titleLabel.textColor = [titleTextAttrs objectForKey:UITextAttributeTextColor];
titleLabel.shadowColor = [titleTextAttrs objectForKey:UITextAttributeTextShadowColor];
if ([titleTextAttrs objectForKey:UITextAttributeTextShadowOffset]){
titleLabel.shadowOffset = [[titleTextAttrs objectForKey:UITextAttributeTextShadowOffset] CGSizeValue];
}
titleView = titleLabel;
}
FRLayerChromeView *chromeView = [self valueForKeyPath:@"chromeView"];
[chromeView.titleView removeFromSuperview];
chromeView.titleView = titleView;
[chromeView addSubview:chromeView.titleView];
[chromeView setNeedsLayout];
}
@end
Use it like this self.layeredNavigationItem.layerController hackSetTitleView:
.
Will create a Pull Request for a proper fix later next week. :)
Cool, thank you!
Very cool :)
On 9 Jan 2013, at 16:36, Ullrich Schäfer notifications@github.com wrote:
FYI: I hacked it for now by adding this category on FRLayerController:
@implementation FRLayerController (Hack)
(void)hackSetTitleView:(UIView )titleView; { if (titleView == nil) { UILabel titleLabel = [[UILabel alloc] init]; const NSDictionary *titleTextAttrs = [[FRNavigationBar appearance] titleTextAttributes];
titleLabel.backgroundColor = [UIColor clearColor]; titleLabel.text = self.layeredNavigationItem.title; titleLabel.textAlignment = UITextAlignmentCenter; titleLabel.font = [titleTextAttrs objectForKey:UITextAttributeFont]; titleLabel.textColor = [titleTextAttrs objectForKey:UITextAttributeTextColor]; titleLabel.shadowColor = [titleTextAttrs objectForKey:UITextAttributeTextShadowColor]; if ([titleTextAttrs objectForKey:UITextAttributeTextShadowOffset]){ titleLabel.shadowOffset = [[titleTextAttrs objectForKey:UITextAttributeTextShadowOffset] CGSizeValue]; } titleView = titleLabel;
} FRLayerChromeView *chromeView = [self valueForKeyPath:@"chromeView"]; [chromeView.titleView removeFromSuperview]; chromeView.titleView = titleView; [chromeView addSubview:chromeView.titleView]; [chromeView setNeedsLayout]; }
@end Use it like this self.layeredNavigationItem.layerController hackSetTitleView:.
Will create a Pull Request for a proper fix later next week. :)
— Reply to this email directly or view it on GitHub.
example code to reproduce problem.