文本不适合特定字体的UIButton titleLabel高度

Joa*_*olt 9 fonts objective-c uibutton ios

我使用的特定字体遇到了一些麻烦.它是为学校制作的,因此A和Å的高度不同.我认为这会给我的UIButton带来麻烦.我试图解决它,但似乎无法做到正确.这是我上次尝试过的:

[self setValue:[UIFont fontWithName:@"fontname" size:220] forKeyPath:@"button1.font"];
[self setValue:[UIFont fontWithName:@"fontname" size:220] forKeyPath:@"button2.font"];
[self setValue:[UIFont fontWithName:@"fontname" size:220] forKeyPath:@"button3.font"];
[button1 setTitle:@"A" forState:UIControlStateNormal];
[button2 setTitle:@"Å" forState:UIControlStateNormal];
[button3 setTitle:@"Å" forState:UIControlStateNormal];
[button2 setBackgroundColor:[UIColor blackColor]];
[button2 setFrame:CGRectMake(button2.frame.origin.x, button2.frame.origin.y, button2.frame.size.width, button2.frame.size.height+100)];
[button2.titleLabel setFrame:CGRectMake(button2.frame.origin.x, button2.frame.origin.y, button2.frame.size.width, button2.frame.size.height)];
button2.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
Run Code Online (Sandbox Code Playgroud)

这是结果:

Å未正确显示.

如您所见,Å未正确显示.我怎样才能解决这个问题?

谢谢!

最好的问候,Joakim

YuA*_*Lai 16

我用以下方法解决了这个问题.

假设你的xib或storyboard中有一个UIButton

  1. 选择UIButton
  2. 转到属性检查器
  3. 查找控件类别
  4. 查找对齐方式
  5. 选择Vertical属性的最右侧按钮!

在此输入图像描述


Joa*_*olt 1

我自己发布了这个问题的另一个答案。\n在我遇到其他字体问题后,我决定在字体编辑器中编辑字体,我使用了字形。\n当我在对其他字符进行一些编辑后导出字体时,\xc3\ x85 开始在我的应用中工作。\n因此,在代码中进行自定义优化之前,请尝试使用字体编辑器重新生成字体。

\n