您的位置:首页 > 产品设计 > UI/UE

UIFont设置

2015-07-22 16:49 459 查看
+ (UIFont *)preferredFontForTextStyle:(NSString *)style

style:

UIKIT_EXTERNNSString *const UIFontTextStyleHeadlineNS_AVAILABLE_IOS(7_0);
UIKIT_EXTERNNSString *const UIFontTextStyleBodyNS_AVAILABLE_IOS(7_0);
UIKIT_EXTERNNSString *const UIFontTextStyleSubheadlineNS_AVAILABLE_IOS(7_0);
UIKIT_EXTERNNSString *const UIFontTextStyleFootnoteNS_AVAILABLE_IOS(7_0);
UIKIT_EXTERNNSString *const UIFontTextStyleCaption1NS_AVAILABLE_IOS(7_0);
UIKIT_EXTERNNSString *const UIFontTextStyleCaption2NS_AVAILABLE_IOS(7_0);

+ (UIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize;

fontName:
NSArray *fontFamilies = [UIFontfamilyNames];
NSLog(@"%@",fontFamilies);

根据Rect设置Font size

int currentFontSize = 17.0;
CGSize requiredSize = [str boundingRectWithSize:maxSize
options:NSStringDrawingUsesFontLeading
attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:currentFontSize]}
context:nil].size;
if(requiredSize.height <= maxSize.height){
while (requiredSize.height <= maxSize.height && requiredSize.width <= maxSize.width) {
currentFontSize ++;
requiredSize = [str boundingRectWithSize:maxSize
options:NSStringDrawingUsesFontLeading
attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:currentFontSize]}
context:nil].size;
}
}else{
while (requiredSize.height > maxSize.height || requiredSize.width > maxSize.height) {
currentFontSize --;
requiredSize = [str boundingRectWithSize:maxSize
options:NSStringDrawingUsesFontLeading
attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:currentFontSize]}
context:nil].size;

}
requiredSize = [str boundingRectWithSize:maxSize
options:NSStringDrawingUsesFontLeading
attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:currentFontSize]}
context:nil].size;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: