[英]Why does border thickness change with color of button (blue gets 2px border)?
[英]IOS Button border thickness lssue,why?
UIButton
顶部边框看起来比下面的边框粗,但有时是正确的 ,为什么?
码:
UIImage * sanImage = [UIimage imageNamed:@"product_bt1_normal"];
[self.saveBtn setBackgroundImage:[sanImage
stretchableImageWithLeftCapWidth:sanImage.size.width/3
topCapHeight:sanImage.size.height/3] forState:UIControlStateNormal];
您是否要按下按钮? 如果是这样,也许改用UIButton? 您可以使用button.layer.borderWidth = 1.0f
控制边框
如果您打算使用图像,请创建一个UIImageView,然后以这种方式修改边框的粗细:
UIImageView *iv = [[UIImageView alloc] initWithImage:sanImage];
[iv.layer setBorderWidth:0.5f];
这可能是由于像素外边界造成的。 由于您使用的是height / 3.0f,因此您的图像可能无法返回正常的图像。
另外,您应该使用一种新的可拉伸图像方法resizableImageWithCapInsets:。
因此,请尝试以下代码:
[self.saveBtn setBackgroundImage:[sanImage resizableImageWithCapInsets:UIEdgeInsetsMake(3.0f, 3.0f, 3.0f, 3.0f)] forState:UIControlStateNormal];
您可能需要稍微弄乱插图的值,但我不知道按钮图像的尺寸。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.