ios11 left/rightBarButtonItems使用

2018-08-02  本文已影响16人  錒伟

BarButtonItems使用文字大小正常,但是用图片就显示异常

试过了imageView也不可以 , 是这样的 WechatIMG2.jpeg

下面终极解决记录:

UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
    [btn.widthAnchor constraintEqualToConstant:30].active = YES;
    [btn.heightAnchor constraintEqualToConstant:30].active = YES;
    [btn setImage:GetImage(@"add") forState:UIControlStateNormal];
    UIBarButtonItem * rightBar = [[UIBarButtonItem alloc]initWithCustomView:btn];
    self.navigationItem.rightBarButtonItem = rightBar;
    [btn addTarget:self action:@selector(clickAddBtn) forControlEvents:UIControlEventTouchUpInside];
上一篇下一篇

猜你喜欢

热点阅读