Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6699921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:45:12+00:00 2026-05-26T06:45:12+00:00

I have a view and I am creating a UILabel programatically and calling it

  • 0

I have a view and I am creating a UILabel programatically and calling it my parameter passing as I need many UILabel text with Different Position frame, so I am calling it by parameter passing.

Using the code below, when I rotate to landscape mode the portrait view Label still appears. How do I overcome this? I need to be done in the below code. I want the position of the Label frame to be changed from portrait view to landscape view.

NOTE:I need to Create many Label,s around 15 to 20, so I am using parameter passing, so that I don’t need to write as many methods for creating each label.

-(UILabel*)createLabel:(CGRect)frame :(NSString*)labelTitle
{
    UILabel *myLabel = [[UILabel alloc] initWithFrame:frame]; 
    [UIFont fontWithName:@"Arial" size:13];  
    myLabel.text = labelTitle;     
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{ 
    if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        [self.view addSubview:[self createLabel:CGRectMake(450,140,60,20):@"Ratings:"]];  
        [self.view addSubview:[self createLabel:CGRectMake(450,170,60,20):@"Reviews:"]];  
    }
    else
    {
        [self.view addSubview:[self createLabel:CGRectMake(650,140,60,20):@"Ratings:"]];
        [self.view addSubview:[self createLabel:CGRectMake(650,170,60,20):@"Reviews:"]];  
    }

    return YES;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:45:13+00:00Added an answer on May 26, 2026 at 6:45 am

    Don’t create them in shouldAutorotateToInterfaceOrientation, because it will get called everytime the orientation changes, thus creating more labels.

    Instead create them once in - (void) loadView, and give them the correct autoResizingMask properties, e.g:

    myLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth ;
    

    This will cause the desired behaviour when the orientation changes: the labels will automatically resize and the whole turning animation will be smooth.

    PS: Mind that the way you were creating Labels is causing a memory leak, use the release method to prevent this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a form using WPF with MVVM. There I have my View with
I am using the following code to for Creating UILabel s and calling it
I have such view that handles user registration. After creating new user i want
I have a view using a master page that contains some javascript that needs
I am creating an application using the MVVM pattern and somewhere I have a
I have a list view that is displaying data using the gridview. This list
I am creating a section view programmatically and I have a UIButton delete also
I have a View for creating a customer that contains numerous textboxes. After the
I have created public synonym as suggested in my other question about creating view
I have followed this tutorial http://blogs.wrox.com/article/creating-a-simple-ipad-application-table-view/ (creating a uitableview and populating it). I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.