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

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

 

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


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

posted @ 2017-11-21 11:05  ma_fighting  阅读(2016)  评论(0)    收藏  举报
历史天气查