美文网首页
IOS 导航栏设置

IOS 导航栏设置

作者: Gwyneth143 | 来源:发表于2017-03-02 09:53 被阅读0次

一、修改导航栏背景色

[self.navigationController.navigationBar setBarTintColor:[UIColor blueColor]];

或者是:

[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];

二、修改导航栏字体颜色

[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil]];

[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];

三、导航栏添加背景图片

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];

四、添加多个栏按钮项目

UIBarButtonItem *shareItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action: nil nil];

UIBarButtonItem *cameraItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action: nil nil];

NSArray *itemsArr = @[shareItem,cameraItem];

self.navigationItem.rightBarButtonItems = itemsArr;

五、自定义后退按钮的文字和颜色

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];

self.navigationItem.backBarButtonItem = item;

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

//自定义返回按钮

UIImage *backButtonImage = [[UIImage imageNamed:@"fanhui.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 0, 0)];

[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

//将返回按钮的文字position设置不在屏幕上显示

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];

相关文章

网友评论

      本文标题:IOS 导航栏设置

      本文链接:https://www.haomeiwen.com/subject/fhdhgttx.html