ios圖片的展開

來源:互聯網
上載者:User

標籤:ios6   技術分享   影響   使用   int   http   ios圖片   pca   高度   

http://blog.csdn.net/q199109106q/article/details/8615661
  1. - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight;  
  
  1. // width為圖片寬度  
  2. rightCapWidth = width - leftCapWidth - 1;  
  3.   
  4. // height為圖片高度  
  5. bottomCapHeight = height - topCapHeight - 1  

 

經過計算,你會發現中間的可展開地區只有1x1

 

[java] view plain copy 
  1. // stretchWidth為中間可展開地區的寬度  
  2. stretchWidth = width - leftCapWidth - rightCapWidth = 1;  
  3.       
  4. // stretchHeight為中間可展開地區的高度  
  5. stretchHeight = height - topCapHeight - bottomCapHeight = 1;  

 

因此,使用這個方法只會展開圖片中間1x1的地區,並不會影響到邊緣和角落。

下面示範下方法的使用:

[java] view plain copy 
  1. // 左端蓋寬度  
  2. NSInteger leftCapWidth = image.size.width * 0.5f;  
  3. // 頂端蓋高度  
  4. NSInteger topCapHeight = image.size.height * 0.5f;  
  5. // 重新賦值  
  6. image = [image stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:topCapHeight];  
  1. - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets  
  1. CGFloat top = 25; // 頂端蓋高度  
  2. CGFloat bottom = 25 ; // 底端蓋高度  
  3. CGFloat left = 10; // 左端蓋寬度  
  4. CGFloat right = 10; // 右端蓋寬度  
  5. UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);  
  6. // 伸縮後重新賦值  
  7. image = [image resizableImageWithCapInsets:insets];  

三、iOS 6.0

在iOS6.0中,UIImage又提供了一個方法處理圖片展開

 

[java] view plain copy 
  1. - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode  

 

對比iOS5.0中的方法,只多了一個UIImageResizingMode參數,用來指定展開的模式:

  • UIImageResizingModeStretch:展開模式,通過展開UIEdgeInsets指定的矩形地區來填充圖片
  • UIImageResizingModeTile:平鋪模式,通過重複顯示UIEdgeInsets指定的矩形地區來填充圖片
    可以拿到圖片直接在xcode右側設定,會自動計算保護地區 

ios圖片的展開

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.