Wednesday, March 6, 2013

How to make UIButton text left (or right) aligned?

It's a really common question and the answer is:

[button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];

Of course, there is also:

[[button titleLabel] setTextAlignment:NSTextAlignmentLeft];

The difference is that the first method sets alignment of the button content, and the second one sets the alignment of the text in the label. But the label frame is as wide as the text is. So if the label has only 1 line, it will always be centered.

Tuesday, March 5, 2013

How to check if app is run under iPhone 5 (the one with 4" screen)?

Sometimes you need to check if app is run under iPhone 5 which has higher screen resolution than previous models. This code should be helpful:

- (BOOL)isIPhone5
    return [[UIScreen mainScreen] bounds].size.height == 568;