设置导航栏标题并添加图片

在开发过程中,很多时候给导航栏设置一个title不能满足项目的需求,有时候我们还要给这个title添加相应的图片,具体做法如下。

    //创建一个Base视图
    UIView *titleBaseView = [[UIView alloc] initWithFrame:CGRectMake((WIDTH_VIEW - 70)/2, 11, 70, 22)];
    //titleBaseView.backgroundColor = [UIColor redColor];
    //创建一个ImageView
    UIImageView *titleImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"倒计时"]];
    //创建一个Label
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(22, 0, 70 - 22, 22)];
    titleLabel.font = [UIFont systemFontOfSize:18.0];
    titleLabel.textColor = TITLE_COLOR_DEEP;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"时间";
    //将两个控件添加到Base视图上
    [titleBaseView addSubview:titleImageView];
    [titleImageView addSubview:titleLabel];
    
    //将Base视图设置为导航栏标题视图
    self.navigationItem.titleView = titleBaseView;

复制代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值