Reputation: 135
I am trying to make a label which displays properly on both landscape and portrait mode. The label looks fine when i am in portrait mode but when i switch to the landscape mode the label is not aligned correctly.Is there a way to adjust the UIlabel automatically when the screen is switched from one mode to another.
Edit: This is the code that i have
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(100 , 100, 100, 100)];
[label setText:@"xxx."];
label.adjustsFontSizeToFitWidth=YES;
[self.view addSubview:label];
[label release];
I have also created a NStimer method which discards the label after 5 seconds
Upvotes: 0
Views: 1026
Reputation: 3605
use autoresizingMask
lblBookmarkName.autoresizingMask = UIViewAutoresizingFlexibleWidth;
Upvotes: 0
Reputation: 3240
I think, you mean shifting of your label.
You can use autoresizingMask
. For example, for connecting label with left part of the screen:
yourLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
Upvotes: 1
Reputation: 61
What do you mean by automatically, and how do you want it to be aligned?
You could add code to -willRotateToInterfaceOrientation:duration:
to give the UILabel
a new frame- but it's hard to post the exact code unless you're specific about what you want the label to do.
Upvotes: 6