如何更改UISegmentedControl上文本的字体大小?

时间:2010-08-16 13:55:30

标签: ios fonts size uisegmentedcontrol

以下是初始化 UISegmentedControl 的代码。

- (void)initializeToolButtons
{
    NSArray *buttonTitles = [NSArray arrayWithObjects:@"ANNEXET", @"HOVET", @"GLOBEN", "ALL", nil];

    toolbuttons = [[UISegmentedControl alloc] initWithItems:buttonTitles];
    toolbuttons.segmentedControlStyle = UISegmentedControlStyleBar;
    toolbuttons.tintColor = [UIColor darkGrayColor];
    toolbuttons.backgroundColor = [UIColor blackColor];     
    toolbuttons.frame = CGRectMake(0, 0, 320, 30);

    [toolbuttons addTarget:self action:@selector(toolButtonsAction) forControlEvents:UIControlEventValueChanged];

    [self.view addSubview:toolbuttons];
}

如何减少 UISegmentedControl 上每个项目的字体大小?

注意: toolButtons 已在全球范围内宣布。

3 个答案:

答案 0 :(得分:13)

很简单:

UIFont *Boldfont = [UIFont boldSystemFontOfSize:16.0f];
    NSDictionary *attributes = [NSDictionary dictionaryWithObject:Boldfont forKey:UITextAttributeFont];
    [segment setTitleTextAttributes:attributes forState:UIControlStateNormal];

答案 1 :(得分:3)

考虑重新设计界面或使用字体较小的“tab”样式。使用未曝光属性可能会导致您的应用被拒绝,或者如果他们更改了内容,则可能会破坏您的应用。

例如,给出的代码示例不起作用。当您点击某个细分时,该细分的字体会重置为正常大小。如果您做的事情偏离了这些事情的正常使用,那么任何不可预测的事情都会在您的应用中发生或改变。因此,如果您希望在以下操作系统更新中继续使用的应用程序坚持使用标准内容,或者使用UIButtons和矩形背景图像制作您自己的控件。黑客攻击现在可能会起作用,但它不会在将来发生。

答案 2 :(得分:0)