简体   繁体   中英

How to Set The Length Size of A UIButton Border Programmatically

I need to set the length size of a UIButton border. I tried using this

[[jb layer] setBorderLength:2.2f];

but got a error saying "setBorderLength is not a method".

Here's my code for my UIButton border:

[[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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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