简体   繁体   English

如何以编程方式设置UIButton边框的长度大小

[英]How to Set The Length Size of A UIButton Border Programmatically

I need to set the length size of a UIButton border. 我需要设置UIButton边框的长度大小。 I tried using this 我尝试使用这个

[[jb layer] setBorderLength:2.2f];

but got a error saying "setBorderLength is not a method". 但出现错误,提示“ setBorderLength不是方法”。

Here's my code for my UIButton border: 这是我的UIButton边框的代码:

[[jb layer] setBorderWidth:2.2f];
[[jb layer] setBorderColor:[UIColor blackColor].CGColor];

setting a layer border parameters : 设置图层边框参数:

jb.layer.borderColor = [UIColor blackColor].CGColor;


jb.layer.borderWidth = 1;


jb.layer.cornerRadius = jb.bounds.size.width * 0.1;

There is no border length. 没有边框长度。 The border width determines how thick your border is. 边框宽度决定了边框的厚度。 The border is around your frame. 边框在您的框架周围。 If you mean your border to be appear wider around your button consider changing the frame. 如果您的意思是边框在按钮周围显得更宽,请考虑更改边框。

You would have to create layers and add it to the button to handle this scenario 您必须创建图层并将其添加到按钮中以处理这种情况

CALayer * layer = [CALayer layer];
layer.bounds = CGRectMake(0, 0, buttonWidth, 1.0);
layer.backgroundColor = [UIColor blackColor].CGColor;
layer.opacity = 0.1f;
[self.button.layer addSublayer:layer];

This will add border on only the top border of button. 这将仅在按钮的顶部边框上添加边框。 Change the frame and add 3 more layers to cover left right and bottom 更改框架并添加3层以覆盖左右和底部

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM