IOS做類似android的.9展開圖

來源:互聯網
上載者:User
UIView's contentStretch (view的伸和縮)

網上有關contentStretch的資料不多,對著官方文檔,花了點時間研究了一下。

做個記錄:

當1.png大於imageV的大小時,1.png就縮小。

當1.png小於imageV的大小時,1.png就放大。

放大:

imageV.image = [UIImage imageNamed:@"1.png"];

 [imageV setContentStretch:CGRectMake(150.0/300.0,75.0/150.0,10.0/300.0,10.0/150.0)];

1.png的大小是 210.0  x  126.0  ;

imageV的frame是(9,117,300,150);

150.0/300.0表示x軸上,前150個像素不進行展開。

75.0/150.0表示y軸上,前75個像素不進行展開。

10.0/300.0表示x軸上150後的10個像素(151-160)進行展開,直到1.png鋪滿imageV。

10.0/150.0表示y軸上75後的10個(76-85)像素進行展開,直到1.png鋪滿imageV。

1.png(原圖,圖是隨手拿的。。。。)

展開後

縮小:

    imageV.image = [UIImage imageNamed:@"j.png"];

    [imageV setContentStretch:CGRectMake(50.0/imageV.frame.size.width, 

                                         50.0/imageV.frame.size.height, 

                                         (imageV.frame.size.width-100.0)/imageV.frame.size.width, 

                                         (imageV.frame.size.height-100.0)/imageV.frame.size.height)];

原圖 

壓縮後 300X240

imageV大小 200 X 150
轉自:http://hi.baidu.com/jt_one/blog/item/937b6e81932a58c3bc3e1e9b.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.