navigationItem的背景修改方法
网上介绍最多的方法是使用分类 但是我用着的时候 不是每次都管用 但是还是先把这个方法写一下吧 毕竟也成功过。
@implementation UINavigationBar (UINavigationBarCategory)
// 设置左边的按钮
UIBarButtonItem *returnButton = [[UIBarButtonItem alloc]initWithTitle:@”返回“ style:UIBarButtonItemStyleBordered target:self action:@selector(returnMain)];
self.navigationItem.leftBarButtonItem = returnButton;
[returnButton release];
//定义右边按钮
UIBarButtonItem *diquButtons = [[UIBarButtonItem alloc]initWithTitle:@”编辑“ style:UIBarButtonItemStyleBordered target:self action:@selector(selectArea)];
self.navigationItem.rightBarButtonItem = diquButtons;
self.diquButton = diquButtons;
[diquButtons release];
[temp release];
但是如果该方法不是很好用的话 只有用这个方法了
- (void)initNavBarItems:(NSString *)titlename{
// 设置navbar的titleview
UIView *dd = [[UIView alloc]initWithFrame:CGRectMake(-5, 0, 325, 44)];
UIImageView *imgs = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"new-nav-bg.png"]];
imgs.frame = CGRectMake(-5, 0, 325, 44);
[dd addSubview:imgs];
// 设置标题
UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(-5, 3, 320, 40)];
title.text = titlename;
title.textAlignment = UITextAlignmentCenter;
title.backgroundColor = [UIColor clearColor];
title.textColor = [UIColor whiteColor];
title.font = [UIFont boldSystemFontOfSize:22];
[dd addSubview:title];
// 设置左边的按钮
UIButton *left = [UIButton buttonWithType:UIButtonTypeRoundedRect];
left.frame = CGRectMake(15, 5, 60, 30);
[dd addSubview:left];
文章来源:毛蛋网(maoegg.com)




评论
发表评论 反向链接