2013-03-27 52 views
5

在iOS 6.0中,UIView的contentStretch屬性已被棄用。 我怎樣才能實現與新/舊/其他API相同的功能?替換爲UIView的contentStretch?

我正在尋找的功能只是在UIButton上延伸圖像的一部分(除邊緣外的所有東西)。

回答

5

使用resizableImageWithCapInsets和UIEdgeInsets創建一個伸展UIButton背景圖像。例如:

UIImage* image = [UIImage imageNamed:@"image.png"]; 
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(0, 20, 0, 20)]; 
[button setBackgroundImage:image forState:UIControlStateHighlighted]; 

我不認爲你可以拉伸超過一個像素水平和垂直。

希望這會有所幫助。