在开发过程中,很多时候给导航栏设置一个title不能满足项目的需求,有时候我们还要给这个title添加相应的图片,具体做法如下。
UIView *titleBaseView = [[UIView alloc] initWithFrame:CGRectMake((WIDTH_VIEW - 70)/2, 11, 70, 22)];
UIImageView *titleImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"倒计时"]];
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 = @"时间";
[titleBaseView addSubview:titleImageView];
[titleImageView addSubview:titleLabel];
self.navigationItem.titleView = titleBaseView;