iPhone UIFont boldFont With name

时光怂恿深爱的人放手 提交于 2020-01-04 12:48:05

问题


I have looked at the headers for UIFont but it has all class methods and only one instance method and some useless properties. I would like to know how to set the font to have a font name, and bold font weight kinda like [[UIFont alloc] initWithFontName:@"Courier New" weight:@"Bold" size:14];. Thanks for any help in advance!

~Thommy


回答1:


I figured out the answer, and that was to use the font-family's bolded version of the font: CourierNewPS-BoldMT and that worked :

I found this out by using the [UIFont fontNamesForFamilyName:@"Courier New"] method which returned an array of all the different variations of Courier New including, Bolded and Italic etc.




回答2:


I added a category to UIFont to do this, provided the Bold version of the font contains the word bold...

- (UIFont *)boldFont {
    NSArray *fontNames = [UIFont fontNamesForFamilyName:self.familyName];
    for (NSString *fontName in fontNames) {
        NSString *upperCaseFontName = [fontName uppercaseString];
        if ([upperCaseFontName rangeOfString:@"BOLD"].location != NSNotFound) {
            return [UIFont fontWithName:fontName size:self.pointSize];
        }
    }
    return self;
}



回答3:


A Google search turns up this list of available iPhone font names.



来源:https://stackoverflow.com/questions/3783608/iphone-uifont-boldfont-with-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!