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 8813945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:59:14+00:00 2026-06-14T03:59:14+00:00

I started up an Xcode project using the ‘single view’ application template and added

  • 0

I started up an Xcode project using the ‘single view’ application template and added two lines to the template-created ViewController class in viewDidLoad:

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectInset(self.view.bounds, 10, 10)];
[self.view addSubview:textView];

When I run this in the 3.5 inch iPhone simulator, the textview extends off the bottom of the screen. I intended for it to be placed in the center of the screen with a 10 point border.

Am I missing something basic? It seems to work fine in the 4″ simulator. Is it a simulator bug?

  • 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-06-14T03:59:15+00:00Added an answer on June 14, 2026 at 3:59 am

    It’s not a bug in the simulator.

    The Xcode template includes a xib, and in that xib is the view controller’s top-level view (self.view), and that view is sized for the iPhone 5 screen.

    When the system sends viewDidLoad to your view controller, it hasn’t yet resized that view for the screen size of the current device. So your text view’s frame is based on the size of an iPhone 5 screen.

    You can fix this by setting the autoresizing flags on your view:

    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectInset(self.view.bounds, 10, 10)];
    [self.view addSubview:textView];
    textView.autoresizingMask = UIViewAutoresizingFlexibleHeight
        | UIViewAutoresizingFlexibleWidth;
    

    Your xib is set up to use autolayout by default, so you can also have the system resize your text view by setting constraints between your text view and your top-level view:

    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectInset(self.view.bounds, 10, 10)];
    [self.view addSubview:textView];
    textView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addConstraints:[NSLayoutConstraint
        constraintsWithVisualFormat:@"H:|-10-[textView]-10-|" options:0 metrics:nil
        views:NSDictionaryOfVariableBindings(textView)]];
    [self.view addConstraints:[NSLayoutConstraint
        constraintsWithVisualFormat:@"V:|-10-[textView]-10-|" options:0 metrics:nil
        views:NSDictionaryOfVariableBindings(textView)]];
    

    If you put your text view in the xib instead of creating it in code, you can use the xib editor (aka “Interface Builder” or “IB”) to set up the constraints. I highly recommend watching the autolayout videos from WWDC 2012:

    • Session 202 – Introduction to Auto Layout for iOS and OS X
    • Session 228 – Best Practices for Mastering Auto Layout
    • Session 232 – Auto Layout by Example
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I started up an Xcode project using the 'single view' application template and added
I started a project in Xcode 4.2 using tab view template. In the app
I have started a project from an XCode template I have created. When I
I have started a project in Xcode 3.x using the Create a Window-Based Application
I started a new IOS app project in Xcode 4.3.1. I selected tabbed application
When I first started using Xcode, I didn't like the default project files location.
Just getting started in xcode 4 and svn, opened my project (had been using
I have a project that I started in xcode 3.x It is using 3
I started to create an app using tabbar app template provided in xcode. Then
I'm running Xcode4.5. Our project started with older Xcode and specifies compiler version using

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.