频道栏目
首页 > 资讯 > IOS > 正文

自定义导航栏按钮

12-04-18        来源:[db:作者]  
收藏   我要投稿

首先,写一个类,继承于UIButton。
 
头文件:
Ios代码 
#import <Foundation/Foundation.h> 
 
@interface BlueButton : UIButton { 
     

 
- (id)init; 
 
@end 
 1 实现文件:
 2 
 3 Ios代码 
 4 #import "BlueButton.h" 
 5  
 6 @implementation BlueButton 
 7  
 8 - (id)init { 
 9   if(self = [super init]) { 
10     self.frame = CGRectMake(0, 0, 49.0, 30.0); 
11     self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
12     self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; 
13          
14     UIImage *image = [UIImage imageNamed:@"blueButton.jpg"]; 
15     UIImage *stretchImage = [image stretchableImageWithLeftCapWidth:15.0 topCapHeight:0.0]; 
16     [self setBackgroundImage:stretchImage forState:UIControlStateNormal]; 
17          
18     self.backgroundColor = [UIColor clearColor]; 
19     [self setTitleShadowColor:[UIColor blackColor] forState:UIControlStateNormal]; 
20     self.titleShadowOffset = CGSizeMake(0, -1); 
21     self.titleLabel.font = [UIFont boldSystemFontOfSize:13]; 
22   } 
23      
24   return self; 
25 } 
26  
27 @end 
28 
29 示例:
30 
31 Ios代码 
32 - (void)viewDidLoad { 
33     [super viewDidLoad]; 
34      
35     BlueButton *blueButton = [[BlueButton alloc] init];  
36     [blueButton setTitle:@"Add" forState:UIControlStateNormal];  
37     [blueButton addTarget:self action:@selector(add) 
38              forControlEvents:UIControlEventTouchUpInside]; 
39      
40     UIBarButtonItem *button = [[UIBarButtonItem alloc] 
41                                                          initWithCustomView:blueButton]; 
42     self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(Cancel)]; 
43     self.navigationItem.rightBarButtonItem = button; 
44      
45     [button release]; 
46     [blueButton release]; 
47 } 
48 


摘自 生活不是用来挥霍的

 


相关TAG标签
上一篇:windows7常见问题的处理
下一篇:清除Win7启动项的方法
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站