您的位置:首页 > 移动开发 > IOS开发

xcode5--ios7自定义导航栏标题、按钮(随笔)

2014-03-17 15:20 127 查看
一、自定义标题:

UILabel *titleText = [[UILabel alloc] initWithFrame: CGRectMake(100, 0, 180, 50)];
titleText.backgroundColor = [UIColor clearColor];
titleText.textColor=[UIColor whiteColor];
titleText.textAlignment=UITextAlignmentCenter;
[titleText setFont:[UIFont systemFontOfSize:17.0]];
[titleText setText:@"选择模式"];
self.navigationItem.titleView=titleText;


二、自定义返回按钮

//自定义返回
UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 100.0, 49.0, 29.0)];
[backBtn setBackgroundImage:[UIImage imageNamed:@"上导航-左返回.png"] forState:UIControlStateNormal];
[backBtn.titleLabel setFont:[UIFont fontWithName:@"Helvetica" size:12]];
[backBtn addTarget:self action:@selector(backOff:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backButtonItem=[[UIBarButtonItem alloc] initWithCustomView:backBtn];
self.navigationItem.leftBarButtonItem = backButtonItem;


三、自定义右侧按钮

//自定义下一步按钮
UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 100.0, 49.0, 29.0)];
[rightBtn setBackgroundImage:[UIImage imageNamed:@"上导航-按钮.png"] forState:UIControlStateNormal];
[rightBtn setTitle:@"下一步" forState:UIControlStateNormal];
[rightBtn.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];
[rightBtn addTarget:self action:@selector(nextStep:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightButtonItem=[[UIBarButtonItem alloc] initWithCustomView:rightBtn];
self.navigationItem.rightBarButtonItem = rightButtonItem;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: