iOS11 自定义UIBarButtonItem显示异常解决方案

本文探讨了在iOS11中遇到自定义UIBarButtonItem加载网络图片时出现的显示异常情况,对比了iOS11之前版本的正常表现,并提供了相应的解决方案。

使用button加载网络图片显示异常
iOS11之前正常:

    self.leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.leftButton addTarget:self action:@selector(leftDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    self.leftButton.frame = RECT(0, 0, 36, 36);
    self.leftButton.clipsToBounds = YES;
    self.leftButton.layer.cornerRadius = 16;
    self.leftButton.layer.borderColor = RGBAHex(0xffffff,0.5).CGColor;
    self.leftButton.layer.borderWidth = 1;
    self.leftButton.adjustsImageWhenHighlighted = NO;
    UIBarButtonItem * leftDrawerButton = [[UIBarButtonItem alloc] initWithCustomView:self.leftButton];
    [self.navigationItem setLeftBarButtonItem:leftDrawerButton animated:YES];

iOS11:

    self.leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.leftButton addTarget:self action:@selector(leftDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    self.leftButton.frame = RECT(0, 0, 36, 36);
    self.leftButton.clipsToBounds = YES;
    self.leftButton.layer.cornerRadius = 16;
    self.leftButton.layer.borderColor = RGBAHex(0xffffff,0.5).CGColor;
    self.leftButton.layer.borderWidth = 1;
    self.leftButton.adjustsImageWhenHighlighted = NO;
    UIBarButtonItem * leftDrawerButton = [[UIBarButtonItem alloc] initWithCustomView:self.leftButton];
    if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 11.0) {
        [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(36, 36));
        }];
    }
    [self.navigationItem setLeftBarButtonItem:leftDrawerButton animated:YES];
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值