2012-03-14 72 views
0

我想在橫向模式下正確拉伸單元格背景。我'寫下了這段代碼:在cell.background視圖中拉伸圖像

UIImage* cellBackGroundImage = [UIImage imageNamed:@"button_listing_default.png"]; 

cellBackGroundImage = [cellBackGroundImage stretchableImageWithLeftCapWidth:290 topCapHeight:76]; 

deselectedBackground = [[UIImageView alloc] initWithImage:cellBackGroundImage] ; 

[deselectedBackground setContentMode:UIViewContentModeScaleToFill]; 

cell.backgroundView = deselectedBackground; 

圖片大小爲580x152。單元格大小爲280x76。

但是,當我將設備變爲橫向時,我的圖像的圓角縮放,但它們不應該。

肖像外觀:Portrait appearance http://xmages.net/storage/10/1/0/6/6/upload/456703d5.png

景觀外貌:Landscape appearance http://xmages.net/storage/10/1/0/d/0/upload/a99fb3a8.png

圖像本身:The image itself http://xmages.net/storage/10/1/0/6/6/upload/e1895d8e.png

回答

0

我發現了什麼導致了我的問題。其實這是圖像本身。當圖像小於結果時,拉伸和自動調整尺寸能正常工作,但如果它應該更寬和更低(就像我的情況那樣),它不會。 所以要解決我的問題,我只是不得不使用較小的圖像。

0

也許你的帽子值是錯誤的?

cellBackGroundImage = [cellBackGroundImage stretchableImageWithLeftCapWidth:290 topCapHeight:76]; 

他們爲什麼這麼大?你的圓角有這麼大的半徑嗎?如果它們只有10px,則比使用stretchableImageWithLeftCapWidth: 10 topCapHeight: 10。這些值定義了圖像的哪一部分不會被縮放。

你可能會告訴我們你的形象嗎?

+0

我曾嘗試過cellBackGroundImage = [cellBackGroundImage stretchableImageWithLeftCapWidth:10 topCapHeight:10];但它沒有幫助 – 2012-03-14 10:16:15

+0

所以這些是你我的視網膜圖像?所以在視網膜的邊緣約爲30px。所以你應該罰款15分的帽值。 (如果這些沒有視網膜圖像,則使用30分)。如果仍然無效,請向我們展示更多代碼。並繼續接受一些問題的答案! – calimarkus 2012-03-14 10:36:53

+0

15和30沒有幫助 – 2012-03-14 12:07:37