Aligning UIButtons/UITextFields in the center
I 开发者_如何转开发know that you can align UILabels in the center by typing this code:
label.textAlignment = UITextAlignmentCenter
Two questions: 1), how do you do the same for UIButtons and UITextFields? And 2), will these objects remain in the center after the device is rotated? Thanks for your help!
1. UIButton has UILabel inside. You can access it via titleLabel
property:
button.titleLabel.textAlignment = UITextAlignmentCenter;
2. Yes, they will remain in center
3. You can find more info about UIButton in UIButton's Class Reference.
精彩评论