项目中,需要使用self.navigationItem.titleView来设置titleview,并且要求达到和屏幕一样宽。
label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
label.text = @"月未央";
label.textAlignment = NSTextAlignmentCenter;
label.backgroundColor = [UIColor redColor];
self.navigationItem.titleView = label;
单纯的设置frame,没有达到预想的效果,效果图如下: