I have text that I want to display centered (both vertically and horizontally) within bounds of a box. The text is dynamic so I can’t just set it in IB.
Anyone have any ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
You can use the following method to get the expected size as
Using this set the frame of your label as
The same could be done with UIButton and UItextArea. You can also you use UITextField but the height would not be adjustible.
Also you can set the
textalignmentproperty to Centre asyourLabel.textAlignment = UITextAlignmentCenterHope it works!!