开发者

Position UILabel when app is opened in iPad

I have a universal iPhone/iPad app. On the main menu I have a UIImage and UILabel that show the current weather conditions outside; the UILabel s开发者_开发问答hows the current temperature.

I am using the same XIB for both versions, I made all of the graphics I am using a high resolution so they scale good for the iPad.

On the iPhone version, right under the UIImage the label is centered, which is what I want it to do. When it loads in the iPad, the UIImage gets a big bigger, but the label stays in the same position, to the left of the screen, not centered under the bigger image. I have tried many different things in IB to get it to center, and I cannot get it to.

Would it also be possible to make the text size bigger when loaded on the iPad?

Here are some images to portray what I am talking about:

iPhone version: http://img855.imageshack.us/i/iphonei.png/

iPad version: http://img163.imageshack.us/i/ipadh.png/


Not sure about your label issue, but to vary text size for iPad create a function to test if you're on an iPad and then use that to vary your code as required. Here's a function to to do the job.

BOOL isIPad()
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
    {
        return YES;
    }
    return NO;
}

And then just write some conditional code. For example:

UIButton *infoCircle;

    if (isIPad())
    {
        infoCircle =  [UIButton buttonWithType:UIButtonTypeInfoDark];
    }
    else
    {
        infoCircle =  [UIButton buttonWithType:UIButtonTypeInfoLight];
    }

In your case, you'll want to adjust the label font size with something like:

if (isIPad())
{
      [[self mainLabel] setFont: [UIFont systemFontOfSize: 18.0]];
}
else
{
      [[self mainLabel] setFont: [UIFont systemFontOfSize: 14.0]];
}

If Interface Builder is giving you grief, you can also use the same approach to reposition the UILabel programmatically. Sometimes this is quicker, especially once your interface has settled down.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜