1. 程式人生 > >iOS11 自定義UIBarButtonItem顯示異常解決方案

iOS11 自定義UIBarButtonItem顯示異常解決方案

使用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];