iOS标题偏移navigationItem,titleLabel,标题偏移到中间开始了,因为要插入图片,所以没有直接用title这个属性
代码如下:
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(-30, 0, 300, 44)];
_titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(-30, 0, 300, 44)];
[view addSubview:_titleLabel];
self.navigationItem.titleView = view;
修改成这样就好了
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(-30, 0, 300, 44)];
_titleLabel = UILabel.new;
[view addSubview:_titleLabel];
[_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.bottom.mas_equalTo(0);
}];
self.navigationItem.titleView = view;
注意:title最好不要用frame不久
网友评论