imageRectForContentRect,titleRectForContentRect,contentRectForBounds,imageRectForContentRect什么時候調用


UIButton的布局順序細節

  什么時候調用imageRectForContentRect,titleRectForContentRect,contentRectForBounds,imageRectForContentRect,也是調用時機。首先梳理清楚幾個布局的規則:

  1. 改變view的size會觸發layoutSubviews
  2. 改變view的x或y不會觸發layoutSubviews
  3. 改變subview的size會觸發superview的layoutSubviews
  4. 改變subview的x或y不會觸發自己以及父視圖的layoutSubviews

記住這幾個布局時的調用順序:

  1. layoutSubviews
  2. backgroundRectForBounds:
  3. contentRectForBounds:
  4. imageRectForContentRect:
  5. titleRectForContentRect:

特別的:

  • 在UIButton初始化階段會依次調用contentRectForBounds:,imageRectForContentRect:。這是在布局之前完成的。
  • 改變title,image,background image都會來到進行綠色文字順序的布局。但不會觸發父視圖的布局,因為UIButton的尺寸未變。
  • 綠色文字區域的調用並不是一次完成。而是復雜的多次調用完成的。它的順序是:3 -> 4 -> 3 -> 5 -> 3 -> 4

轉注出:https://www.cnblogs.com/xiaobajiu/p/11774496.html


免責聲明!

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



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