UIButton背景高度不包装文本(标题) - Swift

时间:2015-08-30 17:06:00

标签: ios swift

UIButton背景的高度(下图中的白色)未完全包裹其文本(标题)。我甚至尝试设置插入(内容),但这不起作用。我做错了什么?

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试使用可调整大小的图像设置背景图像:

UIImage *image = [UIImage imageNamed:@"SomeBackgroundImage"];
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(image.size.height / 2, image.size.width / 2, image.size.height / 2, image.size.width / 2) resizingMode:UIImageResizingModeStretch];
[self setBackgroundImage:image forState:UIControlStateNormal];

夫特:

var image = UIImage(named: "SomeImageName")!;
image = image.resizableImageWithCapInsets(UIEdgeInsetsMake(image.size.height / 2.0, image.size.width / 2.0, image.size.height / 2.0, image.size.width / 2.0), resizingMode: .Stretch)
button.setBackgroundImage(image, forState: .Normal)