0

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

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
user1861763
  • 135
  • 11

3 Answers3

6

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.

1

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;
Eugene Trapeznikov
  • 3,220
  • 6
  • 47
  • 74
0

use autoresizingMask

lblBookmarkName.autoresizingMask = UIViewAutoresizingFlexibleWidth;
Sabareesh
  • 3,585
  • 2
  • 24
  • 42