I have a UITextField
and I want to center this field on the center of the view. Any ideas?
usernameField = [[UITextField alloc] initWithFrame:CGRectMake(0, 200, 200, 28)];
Instead of CGRectMake(some numbers)
- I want to place it in the center of the view.
You can directly assign it the center of the desired view:
usernameField = [[UITextField alloc] initWithFrame:CGRectMake(0, 200, 200, 28)];
usernameField.center = myView.center;
userNameField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 28)];
userNameField.center = CGPointMake(CGRectGetWidth(someView.bounds)/2.0f, CGRectGetHeight(someView.bounds)/2.0f);
Where someView is the superview of userNameField.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With