Setting content edge insets on a UIButton doesn't work as expected
Asked Answered
S

0

11

I have a UIButton that is set up like this:

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.backgroundColor = [UIColor redColor];
[self addSubview:button];
[button setTitle:@"myButton" forState:UIControlStateNormal];

The result looks like this (non red colors are background behind the button):

enter image description here

If I set [button setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)] the result looks the same.

If I set [button setContentEdgeInsets:UIEdgeInsetsMake(1, 0, 1, 0)] the result looks like this:

enter image description here

If I set [button setContentEdgeInsets:UIEdgeInsetsMake(-1, 0, -1, 0)] the result looks like this:

enter image description here

Why does it look like having a positive content inset for top and bottom of 1.0 gives a smaller content inset than 0 (which I understand from the docs is the default)? I am running in Xcode 6 and iOS 7.

Sinus answered 5/10, 2014 at 18:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.