UISegmentedControl字体更改IOS7

时间:2015-09-23 09:31:50

标签: xcode uisegmentedcontrol

我偶然发现了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;

2 个答案:

答案 0 :(得分:0)

请在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")
    }
}

segmentControl IBOutlet的{​​{1}}

如果您想使用UISegmentedControl,则无需打开字体值。在这种情况下使用下面的代码

SystemFont

答案 1 :(得分:0)

UIFont *font = [UIFont boldSystemFontOfSize:8.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font
                                                       forKey:NSFontAttributeName];
[self.segment setTitleTextAttributes:attributes
                            forState:UIControlStateNormal];

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