当我为分段控件设置自定义字体时,它会更改垂直文本对齐方式。我正在使用下面的代码来设置字体。设置自定义字体时的文本对齐问题
// 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];
下面是最新情况的截图。如果你是观察者,文本不是垂直居中对齐。
请帮帮我。先谢谢你 !!
那么当你使用另一种字体(比如标准的iOS)会发生什么?而当你不使用分数字体大小时会发生什么? – bilobatum
@bilobatum如果我使用默认字体,那么文本对齐是完美的。我也尝试将字体大小更改为不同的值,但没有运气,对齐方式不正确。 –
您可以尝试设置文本的背景颜色,并查看文本上方和下方占用的空间量吗?字体可能会在文本上方和/或下方使用一些额外的空白。 –