I want to set the alignment of a text label, how can I do that?
click on Align button on bottom toolbar in IB then select Horizontal or Vertical center. First you might want to fix width and height as well, if you want to preserve size.
You can change label text, label text color, label background color, label border width, label border color by setting it's properties. You can also change the label text alignment by change the UILabel object's textAlignment property value t0 NSTextAlignment. left , NSTextAlignment. center or NSTextAlignment.
I think there are the answers who helped you out. The correct way to do this is:
yourLabelName.textAlignment = NSTextAlignmentCenter;
for more documentation you can read this: https://developer.apple.com/documentation/uikit/uilabel
In Swift :-
yourLabelName.textAlignment = .center
Here .center
is NSTextAlignment.center
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