本文介绍了设置自定义字体时出现文本对齐问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我为分段控件设置自定义字体时,它会更改垂直文本对齐方式。我使用下面的代码来设置字体。
When I set the custom font for the segmented control then it changes the vertical text alignment. I am using below code to set the font .
// I dont think these lines are creating any issue but just wanted to paste all the code
self.segmentType.layer.borderColor = navigationTintColor.CGColor;
self.segmentType.layer.cornerRadius = 0.0;
self.segmentType.layer.borderWidth = 1.5;
// These are the lines that are changing the text alignment
UIFont *font = [UIFont fontWithName:ftHelveticaNeueLTPro_Th size:13.5];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font
forKey:UITextAttributeFont];
[self.segmentType setTitleTextAttributes:attributes
forState:UIControlStateNormal];
以下是最新动态的屏幕截图。如果您是观察者,则文本不是垂直居中对齐的。
Here is the screenshot of whats is happening . If you observer, the text is not vertically centre aligned .
请帮帮我。提前谢谢!!
Please help me . Thank you in advance !!
推荐答案
@Emmanuel建议的以下代码完全正常。您可以更改垂直偏移以在中心垂直对齐文本。
The below code suggested by @Emmanuel works perfectly fine. You can change the vertical offset to align the text vertically at the center .
[self.segmentType setContentPositionAdjustment:UIOffsetMake(0, 2) forSegmentType:UISegmentedControlSegmentAny barMetrics:UIBarMetricsDefault];
这篇关于设置自定义字体时出现文本对齐问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!