首页 > 代码库 > 自定义Navigation按钮及Title
自定义Navigation按钮及Title
导航栏自带的按钮,时常不能满足要求,所以深深需要进行各种定制.
写一个UINavigationItem的category
// UINavigationItem+CB_ChangeButton.h
?
1 2 3 4 5 6 7 8 9 10 | ? @interface UINavigationItem (CB_ChangeButton) - ( void ) CB_SetRightButton:(UIButton *)button; - ( void ) CB_SetLeftButton:(UIButton *)button; - ( void ) CB_SetNavigationTitle:(NSString *)title; @end ? |
// UINavigationItem+CB_ChangeButton.m
?
?
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ?# import "UINavigationItem+CB_ChangeButton.h" @implementation UINavigationItem (CB_ChangeButton) - ( void ) CB_SetRightButton:(UIButton *)button { UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView: button]; self.rightBarButtonItem = rightItem; } - ( void ) CB_SetLeftButton:(UIButton *)button { UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView: button]; self.leftBarButtonItem = leftItem; } - ( void ) CB_SetNavigationTitle:(NSString *)title { UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake( 0 , 0 , 320 , 44 )]; label.text = title; label.textColor = [UIColor whiteColor]; label.font = FONT; label.textAlignment = NSTextAlignmentCenter; self.titleView = label; } @end ? |
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。