前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >iOS8 自定义navigationItem.titleView

iOS8 自定义navigationItem.titleView

作者头像
王大锤
发布2018-05-17 12:12:02
1.3K0
发布2018-05-17 12:12:02
举报
文章被收录于专栏:王大锤王大锤王大锤

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;
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2014-10-20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档