导航栏的一些相关设置

http://blog.csdn.net/jeffasd/article/details/50297363


//    设置左边按钮文字和点击事件

self.navigationItem.leftBarButtonItem =

[[UIBarButtonItem alloc] initWithTitle:@"取消"

style:UIBarButtonItemStyleDone

target:self

action:@selector(cancel)];

//    设置右边按钮文字和点击事件

self.navigationItem.rightBarButtonItem =

[[UIBarButtonItem alloc] initWithTitle:@"发表"

style:UIBarButtonItemStyleDone

target:self

action:@selector(post)];

//    设置title字体大少

NSMutableDictionary *items=[NSMutableDictionary dictionary];

items[NSForegroundColorAttributeName]=[UIColor whiteColor];//字体颜色

items[NSFontAttributeName]=[UIFont systemFontOfSize:17];//字体大小

[self.navigationController.navigationBar setTitleTextAttributes:items];



设置右边BarButtonItem的属性

// 设置item

// UIControlStateNormal正常情况下

NSMutableDictionary *itemAttrs = [NSMutableDictionary dictionary];

itemAttrs[NSForegroundColorAttributeName] = [UIColor blackColor];//颜色,字体

itemAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:17];

[self.navigationItem.rightBarButtonItem setTitleTextAttributes:itemAttrs forState:UIControlStateNormal];

// UIControlStateDisabled不能点击的情况下

NSMutableDictionary *itemDisabledAttrs = [NSMutableDictionary dictionary];//颜色,字体

itemDisabledAttrs[NSForegroundColorAttributeName] = [UIColor lightGrayColor];

[self.navigationItem.rightBarButtonItem setTitleTextAttributes:itemDisabledAttrs forState:UIControlStateDisabled];


当设置UIBarButtonItem的不同状态下的字体颜色或其他属性时,其按钮并不能入愿显示,这是因为navigationController刷新页面的比较慢,所以就不能显示。这时候需要把状态设置的代码都放到-viewDidAppear中

-(void)viewDidAppear:(BOOL)animated

{

[super viewDidAppear:animated];

self.navigationItem.rightBarButtonItem.enabled = NO; // 默认不能点击

// 强制刷新

[self.navigationController.navigationBar layoutIfNeeded];

}

设置导航栏的背景颜色:self.navigationController.navigationBar.barTintColor=[UIColor redColor];

//取消导航条对视图的影响:self.edgesForExtendedLayout = UIRectEdgeNone;



默认使用导航控制器包裹的控制器上第一个(从里到外,从上到下的添加顺序)UIScrollView或其子类会向下偏移64个点,也就是说它的bounds.origin.y = -64.

如果你不想让它偏移64,请在viewDidLoad设置

self.automaticallyAdjustsScrollViewInsets =NO;//默认是YES。

或者:因为系统会默认把View的contenInset的x值加上64,所以我们可以把View的contenInset设置成UIEdgeInsetsMake(-64, 0, 0, 0);

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容