contentView背景图片拉伸

在做聊天界面的时候需要对聊天内容的背景做拉伸,但是一般都是有箭头的不规则的图片,正常拉伸肯定会使图片变形。那要怎么处理呢?

拉伸图片的某个区域
// UIImage方法
// 只用设置capInsets以及UIImageResizingMode
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode NS_AVAILABLE_IOS(6_0); 
// the interior is resized according to the resizingMode

/* UIImage will implement the resizing mode the fastest way possible while
 retaining the desired visual appearance.
 Note that if an image's resizable area is one point then UIImageResizingModeTile
 is visually indistinguishable from UIImageResizingModeStretch.
 */
typedef NS_ENUM(NSInteger, UIImageResizingMode) {
    UIImageResizingModeTile,
    UIImageResizingModeStretch,
};

来个栗子

contentView背景图片拉伸_第1张图片
红色为图片大小,蓝色为拉伸区域_capInsets:UIEdgeInsetsMake(18,25,17,25)
    _msgBGImg.image = [[[UIImage imageNamed:@"LecHisBG"]
                        resizableImageWithCapInsets:UIEdgeInsetsMake(7, 9, 7, 10) resizingMode:UIImageResizingModeStretch]
                       imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

你可能感兴趣的:(contentView背景图片拉伸)