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

  • SEARCH
  • Home
  • 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 695149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:55:47+00:00 2026-05-14T02:55:47+00:00

I created an UIViewController subclass, and figured out that the default implementation of -loadView

  • 0

I created an UIViewController subclass, and figured out that the default implementation of -loadView in UIViewController will ignore my frame size settings in a strange way.

To simplify it and to make sure it’s really not the fault of my code, I did a clean test with a plain instance of UIViewController directly, rather than making a subclass. The result is the same. I try to make an exactly quadratic view of 320 x 320, but the view appears like 320 x 200.

iPhone OS 3.0, please check this out:

UIViewController *ts = [[UIViewController alloc] initWithNibName:nil bundle:nil];
ts.view.frame = CGRectMake(0.0f, 0.0f, 320.0f, 320.0f);
ts.view.backgroundColor = [UIColor cyanColor];
[self.view addSubview:ts.view];

like you can see, I do this:

1) Create a UIViewController instance

2) Set the frame of the view to a quadratic dimension of 320 x 320

3) Give it a color, so I can see it

4) Added it as a subview.

Now the part, that’s even more strange: When I make my own implementation of -loadView, i.e. if I put this code in there like this:

- (void)loadView {
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 320.0f)];
    v.backgroundColor = [UIColor cyanColor];
    self.view = v;
    [v release];
}

then it looks right.

Now lets think about that: In the first example, I do pretty much exactly the same, just that I let UIViewController create the view on it’s own, and then take it over in order to change it’s frame. Right?

So why do I get this strange error? Right now I see no other way of messing around like that to correct this wrong behavior. I did not activate anything like clipsToBounds and there’s no other code touching this.

  • 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-14T02:55:47+00:00Added an answer on May 14, 2026 at 2:55 am

    The dimensions of the view of a view controller should not be changed. It should be autoresized to fit the size of the window or the parent controller.

    If you really need a square view, make a subview.

    // Note: better do this in -loadView or -viewDidLoad.
      UIView* container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
      [ts.view addSubview:container];
      [container release];
      // add stuff into the container view.
      // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a Subclass of UIViewController in my Project and linked it to a
I've created a UIViewController which contains a view with a custom class that I've
I want to create a subclass of UITableView or UIScrollView that will have some
I have a UIViewController subclass which is having its view created programmatically within the
So I have: created a couple of custom controllers (add file UIViewController subclass) in
I created a UITableViewController in a UIViewController subclass and setup delegate methods but the
I've created a UIViewController subclass called addItemToListViewController. I selected add an xib as well,
I have a custom UIViewController subclass and I want to override the loadView method.
I have a strange XCode project compilation issue. I have a subclass of UIViewController
I created a subclass of UITextView and now I want to extend the default

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.