I want create UINavigationBar
custom subclass with multi items. but I don't know about this.
also I want to get this custom NavigationBar
in UIViewControllers
and change it.
please guide me :
1- how to create custom NavigationBar
subclass with items.
2- how to get this custom Nav and change items in it.
this is my code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
ViewController *rootView = [[ViewController alloc]init];
UINavigationController *navi = [[UINavigationController alloc] initWithNavigationBarClass:[NavBar class] toolbarClass:nil];
navi.viewControllers = @[rootView];
self.window.rootViewController = navi;
[window makeKeyAndVisible];
return YES;
}
NavBar.m
#import "NavBar.h"
@implementation NavBar
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self setup];
}
return self;
}
- (void)setup {
[self setupBackground];
}
- (void)setupBackground {
self.backgroundColor = [UIColor clearColor];
self.tintColor = [UIColor blueColor];
// make navigation bar overlap the content
self.translucent = YES;
self.opaque = NO;
// remove the default background image by replacing it with a clear image
[self setBackgroundImage:[self.class maskedImage] forBarMetrics:UIBarMetricsDefault];
// remove defualt bottom shadow
[self setShadowImage: [UIImage new]];
}
+ (UIImage *)maskedImage {
const CGFloat colorMask[6] = {222, 255, 222, 255, 222, 255};
UIImage *img = [UIImage imageNamed:@"nav-white-pixel-bg.jpg"];
return [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
It sounds like what you are looking for is a UISegmentedControl
.
You can either add this to a UINavigationBar
in a storyboard or programmatically.
Definitely give the documentation on UISegmentedControl
's a look as well
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With