【问题标题】:How to change the font size of the text on a UISegmentedControl?如何更改 UISegmentedControl 上文本的字体大小?
【发布时间】:2011-03-30 10:59:53
【问题描述】:

以下是初始化我的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 已在全球范围内声明。

【问题讨论】:

    标签: ios fonts size uisegmentedcontrol


    【解决方案1】:

    很简单:

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

    【讨论】:

    • 在 iOS 7.0 中使用 NSFontAttributeName
    【解决方案2】:

    考虑重新设计您的界面或使用字体较小的“标签”样式。乱用未公开的属性可能会导致您的应用程序被拒绝或破坏您的应用程序,如果它们改变了引擎盖下的某些东西。

    例如,给出的代码示例不起作用。当您点击一个段时,该段的字体会重置为其正常大小。如果你做的事情偏离了这些东西的正常使用,任何不可预测的事情都可能在你的应用程序中发生或改变。因此,如果您想要一个可以在后续操作系统更新中继续工作的应用程序,请坚持使用标准内容,或者使用 UIButtons 和矩形背景图像制作您自己的控件。 hack 现在可能会起作用,但并不是说将来会起作用。

    【讨论】:

      猜你喜欢
      • 2011-01-17
      • 2016-05-22
      • 2015-08-02
      • 2016-11-22
      • 1970-01-01
      • 2015-03-12
      • 2020-12-21
      • 2011-12-08
      • 1970-01-01
      相关资源
      最近更新 更多