【问题标题】:UISegmentedControl Font change IOS7UISegmentedControl IOS7字体改
【发布时间】:2015-09-26 22:29:57
【问题描述】:

我偶然发现了一个 UISegmentedControl,我想调整字体大小,浏览了几个教程但仍然无法修复它,因为所有示例看起来都与我所拥有的不同,并且 InterfaceBuilder 中没有字体选项,所以如何以及实际上我在哪里添加字体标准?谢谢你的帮助。这就是我所拥有的:

- (void)valueChanged:(UISegmentedControl *)segment

{   
if(segment.selectedSegmentIndex == 0) {
    [self getlistInformationbyIdPerson:self.person.id_person withInformationType:1 withCompletion:^{
        [self.personConnectedInformationTableView reloadData];

    }];
}
else if(segment.selectedSegmentIndex == 1){
    [self getlistInformationbyIdPerson:self.person.id_person withInformationType:3 withCompletion:^{
        [self.personConnectedInformationTableView reloadData];

    }];
}
else if(segment.selectedSegmentIndex == 2){
    [self getlistInformationyIdPerson:self.person.id_person withInformationType:2 withCompletion:^{
        [self.personConnectedInformationTableView reloadData];

    }];
}
}

我有这个:

- (NSString *)noSegmentedControlDataLabelForSegment:(NSInteger)aSegment andCelebrity:(NSString *)aCelebrity
{

NSString *noDataMessage;
NSString *segmentText

switch (aSegment) {
    case 0:
        segmentText = @"list1";
        break;
    case 1:
        segmentText = @"list2";
        break;
    case 2:
        segmentText = @"list3";
        break;

    default:
        break;
}

noDataMessage = [NSString stringWithFormat:@"We are sorry to inform you that our dataBase dosen't contain any information"];

return noDataMessage;

}

和.h中的这个

@property(nonatomic,retain) IBOutlet UISegmentedControl *segment;

【问题讨论】:

    标签: xcode uisegmentedcontrol


    【解决方案1】:

    请在viewDidLoad中使用此代码

    override func viewDidLoad() {
        super.viewDidLoad()
        if let font = UIFont(name: "Courier", size: 12.0) {
            print("Font Available")
            let attributes = [NSFontAttributeName : font]
            self.segmentControl.setTitleTextAttributes(attributes, forState: UIControlState.Normal)
        }
        else {
            print("Font not available")
        }
    }
    

    其中segmentControlIBOutletUISegmentedControl

    如果您想使用SystemFont,那么您不必解开字体值。在这种情况下使用下面的代码

    let font = UIFont.systemFontOfSize(12.0)
    let attributes = [NSFontAttributeName : font]
    self.segmentControl.setTitleTextAttributes(attributes, forState: UIControlState.Normal)
    

    【讨论】:

    • 它给了我一个错误:使用未声明的标识符“覆盖”
    • 这个想法是您必须编写此代码,在我的示例中,我已将其添加到 viewDidLoad 方法中,该方法在此处被覆盖。
    • 感谢我在 ViewDid Load 中添加了您提到的版本并且我工作了:
    【解决方案2】:
    UIFont *font = [UIFont boldSystemFontOfSize:8.0f];
    NSDictionary *attributes = [NSDictionary dictionaryWithObject:font
                                                           forKey:NSFontAttributeName];
    [self.segment setTitleTextAttributes:attributes
                                forState:UIControlStateNormal];
    

    将它添加到 ViewDidLoad 为我改变了字体大小,感谢 Inder Kumar 让我走上正轨 :)

    【讨论】:

      猜你喜欢
      • 2011-01-17
      • 1970-01-01
      • 1970-01-01
      • 2012-02-20
      • 2012-05-12
      • 2013-12-06
      • 2013-10-11
      • 1970-01-01
      • 2014-03-03
      相关资源
      最近更新 更多