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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:22:07+00:00 2026-06-07T14:22:07+00:00

I have subclassed a UITableView Cell and I want to programmatically add a UITextField

  • 0

I have subclassed a UITableView Cell and I want to programmatically add a UITextField to it. I have figured out how to create the text field; however, I’m having difficulty resizing it when the device gets rotated. Here is my code (keep in mind that self is a UITableViewCell subclass)

self.myTextField = [[UITextField alloc] init];
self.myTextField.frame = CGRectMake(400, 6,TEXT_FIELD_WIDTH ,TEXT_FIELD_HEIGHT);
[self addSubview:self.myTextField];
self.myTextField.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;

What I want is regardless of the orientation, the textfield to have an x origin at around the center of the screen (around point 400) and I want it to maintain its distance with the right screen edge and expand its width otherwise (flexible left margin).

This works fine if I comment out the autoresizingMask line and I start the device in portrait. However, whenever I add the autoresizing line back in it moves the text field away from point 400, EVEN IN PORTRAIT.

Any suggestions? I’ve tried also adding the textfield to the content view, but this doesn’t seem to change anything.

EDIT: I have thought about using the layoutsubviews method, but this seems kinda crude because I’d have to hard-code in a whole bunch of different coordinates. Thus, if there is another way to do this, that would be preferred.

EDIT: For example, in order to get the textfield to start around the middle I have to give it a frame xOrigin of around 150.

  • 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-07T14:22:09+00:00Added an answer on June 7, 2026 at 2:22 pm

    You are setting wrong the autoresizingMask. You must specify the value combining the constants described in UIViewAutoresizing using the C bitwise OR operator, like:

    self.myTextField.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have few custom controls (image views) added programmatically to table cell. I want
I have subclassed UITableViewCell to make a custom cell for a tableView. I add
Basically I want to re-style UITableView(Controller). Each cell will have a picture as a
I have subclassed a UITableViewCell and within this class I want to get it's
So I have a subclassed UITableView that lists data. I need to make only
I have subclassed a control in C# WinForms, and am custom drawing text in
I have subclassed UITableViewCell for a custom cell view along the lines as follows:
I have a UITableView and I've subclassed UITableViewCell (called it CustomCell ) so it
I have a UITableView with about 20 cells, in each cell there are three
I have a UITableView with each cell containing the following 1) A UILabel (listing

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.