In my app I have a UITextField in a UITableViewCell and currently I have it take up the entire width of the cell because obviously that would be the max it could go.
Anyway, is I know there is the option of using an autoresizingMask like: AutoReszingMaskFlexibleWidth
Anyway, first question, so even if I set the width to lets say 1 in Interface Builder, the UITextField will adjust the width to the width of the text correct?
Second question, is there a way to make a max for the width of the autoresizing mask so that the width doesn’t lets say get to 5000?
Thanks!
First question: no. If you set the width to 1, the text field will initially have width 1. If, after the text field has been added as a subview of the table view cell, the table view cell’s width is changed, the text field’s width will also change. Read “Handling Layout Changes Automatically Using Autoresizing Rules” in the View Programming Guide for iOS.
Second question: autoresizing doesn’t support setting a max width. If you need to enforce a max width, make a subclass of
UITableViewCell, overridelayoutSubviewsin your subclass, and enforce the maximum width in code.