在仿寫QQ會話窗口的時候,氣泡的背景圖片拉伸問題。并不是所有地方都可以拉伸的,所以定義了下面的工具類中的一個方法,專門拉伸圖片。
- UIImageResizingModeStrech:拉伸模式,通過拉伸UIEdgeInsets指定的矩形區域來填充圖片
- UIImageResizingModeTile:平鋪模式,通過重復顯示UIEdgeInsets指定的矩形區域來填充圖片
+ (UIImage *)resizeWithImage:(UIImage *)image{
CGFloat top = image.size.height/2.0;
CGFloat left = image.size.width/2.0;
CGFloat bottom = image.size.height/2.0;
CGFloat right = image.size.width/2.0;
return [image resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right)resizingMode:UIImageResizingModeStretch];
}
顯示樣式:
P.S.
resizableImageWithCapInsets有四個值上下左右
上下左右的值定義了受保護區域,能被拉伸的地方是中間區域,一般我們都設成中心點為了安全。