iOS以编程方式更改字体大小不起作用

时间:2015-02-21 16:27:28

标签: ios objective-c uitableview

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        if ([[UIDevice currentDevice].systemVersion floatValue] < 7.0f) {
            self.textLabel.backgroundColor = [UIColor whiteColor];
        }

        _topUserNewName= [[UILabel alloc] init];
        _topUserNewName.textAlignment = NSTextAlignmentLeft;
        _topUserNewName.backgroundColor = [UIColor clearColor];
        _topUserNewName.font = [UIFont fontWithName:@"HelvaticaNeue-Regular" size:5.0];
        _topUserNewName.textColor = [UIColor colorWithRed:(47/255.0) green:(55/255.0) blue:(65/255.0) alpha:1];
        _topUserNewName.frame = CGRectMake(66, 8, 215, 21);


        _topUserName= [[UILabel alloc] init];
        _topUserName.textAlignment = NSTextAlignmentLeft;
        _topUserName.backgroundColor = [UIColor clearColor];
        _topUserName.font = [UIFont fontWithName:@"HelvaticaNeue-Regular" size:10.0];
        _topUserName.textColor = [UIColor colorWithRed:(145/255.0) green:(212/255.0) blue:(210/255.0) alpha:1];
        _topUserName.frame = CGRectMake(66, 37, 210, 21);


        [self.contentView addSubview:_topUserNewName];
        [self.contentView addSubview:_topUserName];


        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

这个代码在我的表格单元格中。当我改变大小没有任何变化时,我想在这里以编程方式更改字体大小? 我研究谷歌这条规则是正确的,但没有任何想法吗?

2 个答案:

答案 0 :(得分:1)

请确保您传递的是正确的字体系列和字体...此

 [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0];

HelvticaNeue-regular face不受ios支持,您可以通过枚举为:

来检查所有支持的字体
for (NSString *familyName in [UIFont familyNames]){ NSLog(@"Font Family = %@",familyName);
for (NSString *fontName in
[UIFont fontNamesForFamilyName:familyName]){ NSLog(@"\t%@", fontName);
}
}
}

答案 1 :(得分:1)

名称HelveticaNeue-Regular实际上并不存在。这应该是[UIFont fontWithName:@"HelvaticaNeue" size:10.0];

您可以在此处查看所有字体名称列表:http://iosfonts.com/