图片拉升不变形,类似聊天气泡

//标签1

CGSize sizeLabel1 = [[NSString stringWithFormat:@"#%@",arrayFrom[k][@"label"]] sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20.0*HeightProportion]}];

UIButton * buttonLabel1 = [UIButton buttonWithType:UIButtonTypeCustom];

buttonLabel1.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);

[buttonLabel1 setBackgroundImage:[self resizableImageWithName:@"拉伸标签"] forState:UIControlStateNormal];

[buttonLabel1 setTitle:[NSString stringWithFormat:@"#%@",arrayFrom[k][@"label"]] forState:UIControlStateNormal];

[buttonLabel1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

buttonLabel1.titleLabel.font = [UIFont systemFontOfSize:20.0*HeightProportion];

//汉字内部距离

[buttonLabel1 setTitleEdgeInsets:UIEdgeInsetsMake(0, 15.0*WidthProportion, 0, 20)];

[imagePhone addSubview:buttonLabel1];

//图片拉升不变形

- (UIImage *)resizableImageWithName:(NSString *)name{

UIImage *oldImage = [UIImage imageNamed:name];

//    resizableImageWithCapInsets:设定拉伸范围(让图片距离上左下右有多少范围不拉伸)

//    resizingMode:表示拉伸的方法。

CGFloat w = oldImage.size.width * 0.5;

CGFloat h = oldImage.size.height * 0.5;

return [oldImage resizableImageWithCapInsets:UIEdgeInsetsMake(h, w, h, w) resizingMode:UIImageResizingModeStretch];

}

你可能感兴趣的:(图片拉升不变形,类似聊天气泡)