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

自定义导航栏按钮

时间:2016-04-17 14:32:26      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

自定义导航栏按钮

 
添加了UINavigationController后,可以在当前视图控制器修改下一页的返回按钮backBarButtonItem:
 
方法1.  用系统自带的返回按钮

UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc]

                                          initWithTitle:@"返回"

                                          style:UIBarButtonSystemItemCancel

                                          target:self

                                          action:@selector(doClickBackAction:)];

    self.navigationItem.backBarButtonItem = leftBarButtonItem;

 
方法2. 自己定义返回按钮

UIImage* backImage = [UIImage imageNamed:@"btn_back.png"];

    CGRect backframe = CGRectMake(0,0,54,30);

    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];

    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];

    [backButton setTitle:@"直播" forState:UIControlStateNormal];

    backButton.titleLabel.font=[UIFont systemFontOfSize:13];

    [backButton addTarget:self action:@selector(doClickBackAction:)forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backButton];

    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] init];

    self.navigationItem.leftBarButtonItem = leftBarButtonItem;

    [leftBarButtonItem release];

    [backButton release];

 

其实导航栏中所有按钮都可以采用方法而进行自定义。

 

 

自定义导航栏按钮

标签:

原文地址:http://www.cnblogs.com/stevenwuzheng/p/5400939.html

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