Under autolayout your frame sizes will be ignored (the one you use during initWithFrame:
). You've specified positioning constraints, but nothing to do with size, therefore your TextFieldWithLabel
is positioned at the centre of the screen, with size zero.
The text field and label are still visible because you say you are not using autolayout internally in this control - presumably you do set some frames and autoresizing masks inside there. The text field and label are therefore outside the bounds of the TextFieldWithLabel
, so they are visible, but probably don't respond to touches.
To solve this problem you have two options:
- Use autolayout internally - for example, if you have this constraint (in VFL) then it will automatically give a height to your control:
"V:|-[label]-[textField]-|"
Add sizing constraints to your code above - use the same dimensions you did in your initWithFrame. Here is one for setting the height:
[NSLayoutConstraint constraintWithItem:usernameTextField attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant:50.0];
I have a category on UIView to simplify the creation of common constraints here. Using the category code you'd do centerInView:
and constrainToSize: