码迷,mamicode.com
首页 > 其他好文 > 详细

自定义Navigation按钮及Title

时间:2014-05-15 11:28:21      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   java   c   

导航栏自带的按钮,时常不能满足要求,所以深深需要进行各种定制.

写一个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?
?

自定义Navigation按钮及Title,布布扣,bubuko.com

自定义Navigation按钮及Title

标签:style   blog   class   code   java   c   

原文地址:http://www.cnblogs.com/jz319/p/3729283.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!