如何在 iPhone 上设置 NSAtributedString 的字体。我在网上找到了如何为 mac 做这件事,但它不一样。当我试图将它转换为 iOS 平台时,它没有用。我需要设置字体名称和字体大小。
NSDictionary *attributes = [[NSDictionary alloc] initWithObjectsAndKeys:
[UIFont fontWithName:@"Helvetica" size:26], kCTFontAttributeName,
[UIColor blackColor], kCTForegroundColorAttributeName, nil];
最佳答案
查看代码
infoString=@"This is an example of Attributed String";
NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:infoString];
NSInteger _stringLength=[infoString length];
UIColor *_black=[UIColor blackColor];
UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:30.0f];
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSForegroundColorAttributeName value:_black range:NSMakeRange(0, _stringLength)];
关于ios - NSAtributedString 字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11771228/