Ios UISegmentedControl setTitleTextAttributes:forState:无法很好地使用字体

Ios UISegmentedControl setTitleTextAttributes:forState:无法很好地使用字体,ios,attributes,uisegmentedcontrol,uifont,Ios,Attributes,Uisegmentedcontrol,Uifont,我有一个试图自定义的UISegmentedControl,但有两个问题: 这是我的代码: NSDictionary *attributes = @{UITextAttributeFont: [UIFont fontWithName:@"Gotham-Book" size:14.f], UITextAttributeTextColor: [UIColor whiteColor],

我有一个试图自定义的UISegmentedControl,但有两个问题:

这是我的代码:

NSDictionary *attributes = @{UITextAttributeFont: [UIFont fontWithName:@"Gotham-Book" size:14.f],
                                 UITextAttributeTextColor: [UIColor whiteColor],
                                 UITextAttributeTextShadowColor: [UIColor clearColor]};
    [segmentedControl setTitleTextAttributes:attributes forState:UIControlStateNormal];

     NSDictionary *selectedAttributes = @{UITextAttributeFont: [UIFont fontWithName:@"Gotham-Medium" size:14.f],
                                     UITextAttributeTextColor: [UIColor redColor]};
    [segmentedControl setTitleTextAttributes:selectedAttributes forState:UIControlStateSelected];
1 UISegmentedControl对uicontrol状态正常反应良好,但对于forState:UIControlStateSelected,颜色有效,但字体无效。仅供参考,字体存在是因为如果我将Gotham Book和Gotham Medium切换为UIControlStateNormal,我会看到差异

2在我为uicontrol状态设置字体之前,文本是垂直对齐的,但现在不再是了。如何更改文本插图


谢谢你的帮助

如果需要,在IOS 7上使用NSFontAttributeName、NSForegroundColorAttributeName和NSShadowAttributeName

为了向后兼容,我使用了两种变体,如:

NSDictionary *attributes = @{UITextAttributeFont: [UIFont fontWithName:@"Gotham-Book" size:14.f],
                             UITextAttributeTextColor: [UIColor whiteColor],
                             UITextAttributeTextShadowColor: [UIColor clearColor],
                             NSFontAttributeName: [UIFont fontWithName:@"Gotham-Book" size:14.f],
                             NSForegroundColorAttributeName: [UIColor whiteColor],
};
[segmentedControl setTitleTextAttributes:attributes forState:UIControlStateNormal];