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時 不會出現這個問題。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM