解决iOS11中navigationBar上使用initWithCustomView按钮图片错位 frame无效

在iOS11上当使用如下代码设置时

   UIButton *shareButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    shareButton.frame = CGRectMake(0, 0, 30, 30);
    shareButton.backgroundColor = [UIColor blueColor];
    [shareButton setImage:[UIImage imageNamed:@"mv_actionIconSaveToAlbum"]  forState:(UIControlStateNormal)];
    UIBarButtonItem *rightBtnItem = [[UIBarButtonItem alloc] initWithCustomView:shareButton];
    self.navigationItem.rightBarButtonItem = rightBtnItem;

如果图片大小大于按钮设置的大小 ,设置的button的frame将不起作用。系统将采用最大区域展示。图片大小小于设置的button的frame时 不会出现这个问题。

猜你喜欢

转载自blog.csdn.net/HDFQQ188816190/article/details/78353970