Reputation: 1664
This looks like an easy enough question, but I can't seem to find a solution online. I use an UIButton
's layer to make a border for it. And the border shows. The problem is that the paddings (top/right/bottom/left, obviously this term comes from the CSS world) of the border are too small, and I want to increase them. How do I do that?
Here is my code:
myButton.layer.cornerRadius = 10;
myButton.layer.borderWidth = 2;
myButton.layer.masksToBounds = YES;
And the button looks like above.
Upvotes: 3
Views: 2290
Reputation: 16609
In iOS 15, if you use UIButtonConfiguration, It will be :
button.configuration.contentInset = UIEdgeInsets(top: 2, left: 4, bottom: 2, right: 4)
for older version:
button.contentEdgeInsets = UIEdgeInsets(top: 2, left: 4, bottom: 2, right: 4)
Upvotes: 0
Reputation: 4656
Use titleEdgeInsets
Property of UIButton
myButton.titleEdgeInsets = UIEdgeInsets(5, 5, 5, 5);
Adjust the insets as required! You can get more details about titleEdgeInsets
from Apple Docs
Upvotes: 2
Reputation: 990
Try changing the contentEdgeInsets
. These are the outer-most margins for the rectangle surrounding all of the button’s content.
For example: myButton.contentEdgeInsets = UIEdgeInsetsMake(5,5,5,5);
Upvotes: 7
Reputation: 1493
Either you can reduce the button font size like,
myButton.titleLabel.font = [UIFont systemFontOfSize:14.0];
or just change the frame size of button in storyboard or programatically
Upvotes: 0