Showing posts with label iOS. Show all posts
Showing posts with label iOS. Show all posts

Thursday, April 11, 2013

UIWebView and shadow

Last time I was trying to add a shadow to UIWebView. And it wasn't so obvious, because the standard way didn't work:

    webView.layer.shadowRadius = 8;
    webView.layer.shadowOffset = CGSizeMake(00);
    webView.layer.shadowColor = [[UIColor grayColorCGColor];
    webView.layer.shadowOpacity = 1;

But there is a simple solution. You just have to add these 2 lines:

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;
}