Text inside the label is aligned centered horizontally as well as vertically. How do I set the text to align below the mid horizontal axis?
Asked
Active
Viewed 179 times
0
-
picture speak better than words – Vinodh Jun 25 '19 at 06:49
-
Possible duplicate of [Adding space/padding to a UILabel](https://stackoverflow.com/questions/27459746/adding-space-padding-to-a-uilabel) – dahiya_boy Jun 25 '19 at 07:04
-
Question wording is different but this answer will resolve the issue. – dahiya_boy Jun 25 '19 at 07:05
-
Use label insets programmatically. – Abhishek Maurya Aug 12 '19 at 09:55
2 Answers
1
You can do this by subclassing UILabel and override this method
- (void)drawTextInRect:(CGRect)rect {
UIEdgeInsets insets = {6, 5, 0, 5};//{top, left,bottom,right} Change the padding values as your need
[super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)];
}

lazyTank
- 1,783
- 1
- 8
- 11
0
There are many ways to do it. But this is the simplest one.
Create a UIView
Add that Label into that view
Add auto layout constraint to define fixed margin from the bottom of the view.

Ankit Saxena
- 809
- 7
- 10