crazy2431
crazy2431

Reputation: 801

Autoresizingmask in not working for allignment of LAbels on Rotation

I am doing an application where i am creating a UILabels programmitically,As i will be creating some 15 labels with different frames so i using only one method and calling it by parameter passing.

when i rotate it to Landscape view the position of the labels should be changed as there will lot of space left empty at right side..so i am trying to use Autoresizing mask but its not working,so please suggest what i should do so that label frame changes and fits at right position when i turn to landscape orientation. please provide me a sample code.The present code i am using is given below.

{
[self.view addSubview:[self createLabel:CGRectMake(450,140,60,20):@"Ratings:"]];  
[self.view addSubview:[self createLabel:CGRectMake(450,170,60,20):@"Reviews:"]];  
[self.view addSubview:[self createLabel:CGRectMake(50,170,50,20):@"Hours:"]];  
[self.view addSubview:[self createLabel:CGRectMake(50,200,50,20):@"Phone:"]];  

self.view.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
[super viewDidLoad];
}

-(UILabel*)createLabel:(CGRect)frame :(NSString*)labelTitle
{   
UILabel  *myLabel = [[UILabel alloc] initWithFrame:frame]; 

[UIFont fontWithName:@"Arial" size:13];  
myLabel.textAlignment = UITextAlignmentLeft;   
myLabel.font = [UIFont boldSystemFontOfSize:13];
myLabel.text = labelTitle;     
[myLabel autorelease];
return myLabel;
}

Upvotes: 0

Views: 1782

Answers (1)

Nekto
Nekto

Reputation: 17877

You should set also autoresizingMask to all subview of self.view - add, for example, next line in the -(UILabel*)createLabel:(CGRect)frame :(NSString*)labelTitle method:

myLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;

or

myLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth;

Upvotes: 3

Related Questions