iOS开发titleView如何居中展示

只是写label会自适配最大宽度,加入到view中即可
UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screen_allwidth-120, 25)];
UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, titleView.width, 25)];
titleLab.text = customInfoModel.CUST_NAME;
titleLab.textAlignment = NSTextAlignmentCenter;
// titleView.backgroundColor = [UIColor clearColor];
titleLab.font = BoldSystemFont(18);
titleLab.textColor = SXDAColorFromRGB(0x2c2c2c);
[titleView addSubview:titleLab];
self.navigationItem.titleView = titleView;

你可能感兴趣的:(iOS开发titleView如何居中展示)