gpt4 book ai didi

iphone - 如何获取 UIFont 实例的字体大小或粗体版本

转载 作者:IT王子 更新时间:2023-10-29 07:41:57 28 4
gpt4 key购买 nike

如何获取 UIFont 实例的字体大小?

或者,如果有人可以为 UIFont 实现这个方法?

- (UIFont *)boldFont;

最佳答案

这是一个旧答案,不再是最佳解决方案,请改为查看已接受的答案。

-(UIFont *)boldFont{

//First get the name of the font (unnecessary, but used for clarity)
NSString *fontName = self.fontName;

//Some fonts having -Regular on their names. so we have to remove that before append -Bold / -BoldMT
fontName = [[fontName componentsSeparatedByString:@"-"] firstObject];

//Then append "-Bold" to it.
NSString *boldFontName = [fontName stringByAppendingString:@"-Bold"];

//Then see if it returns a valid font
UIFont *boldFont = [UIFont fontWithName:boldFontName size:self.pointSize];

//If it's valid, return it
if(boldFont) return boldFont;

//Seems like in some cases, you have to append "-BoldMT"
boldFontName = [fontName stringByAppendingString:@"-BoldMT"];
boldFont = [UIFont fontWithName:boldFontName size:self.pointSize];

//Here you can check if it was successful, if it wasn't, then you can throw an exception or something.
return boldFont;

}

关于iphone - 如何获取 UIFont 实例的字体大小或粗体版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6544132/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com