My app is using custom font to display an information for the whole app.
But there is some problems with their base line like in the image below:
I need to fix "X 4" to be centered in vertical red box.
How can I fix this?
My app is using custom font to display an information for the whole app.
But there is some problems with their base line like in the image below:
I need to fix "X 4" to be centered in vertical red box.
How can I fix this?
Set attributed string with adjusted baseline offset like so in Swift:
let sttrStr = NSAttributedString.init(string: "your text",
attributes:[NSAttributedStringKey.baselineOffset: -10])
textLabel.attributedText = attrStr
or like so in ObjC:
NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:@"your string"
attributes:@{ NSBaselineOffsetAttributeName : @-10 }];
textLabel.attributedText = attrStr;
Per SO answer here
You can create a UILabel
and set its size same as the red box. And then set it's text alignment as center:
youLabel.textAlignment = NSTextAlignment.Center
Another not so good option is to make a UIButton
of same size as red box and set its UserInteractionEnabled
to No
. This way your text will be positioned in the center horizontally and vertically. You can also set it's setContentVerticalAlignment
property