码迷,mamicode.com
首页 > 移动开发 > 详细

iOS8 自定义navigationItem.titleView

时间:2014-10-20 15:03:31      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   sp   

navigationBar其实有三个子视图,leftBarButtonItem,rightBarButtonItem,以及titleView。前两种的自定义请参考http://www.cnblogs.com/6duxz/p/4030916.html

titleView的自定义就更简单了,把它看成一个视图,替换或者添加子视图都可以。以下我在titleView添加了两个button

UIButton* actionNewButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 50, 40)];
    [actionNewButton setTitle:@"测试1" forState:UIControlStateNormal];
    actionNewButton.tag=0;
    [actionNewButton setTitleColor:[UIColor colorWithRed:0.1 green:0.63 blue:0.96 alpha:0.93] forState:UIControlStateNormal];
    //actionNewButton.backgroundColor=[UIColor grayColor];
    
    UIButton* classicAction = [[UIButton alloc]initWithFrame:CGRectMake(50, 0, 50, 40)];
    [classicAction setTitle:@"测试2" forState:UIControlStateNormal];
    classicAction.tag=1;
    [classicAction setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    //classicAction.backgroundColor=[UIColor blueColor];
    
    UIView* titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
    //titleView.backgroundColor=[UIColor redColor];
    [titleView addSubview:actionNewButton];
    [titleView addSubview:classicAction];
    
    self.navigationItem.titleView=titleView;

 

iOS8 自定义navigationItem.titleView

标签:style   blog   http   color   io   os   ar   for   sp   

原文地址:http://www.cnblogs.com/6duxz/p/4037062.html

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