ios - NSAtributedString 字体

标签 ios nsattributedstring

如何在 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/

相关文章:

ios - 拆分属性字符串并保留格式

ios - iOS6 中的任何 api 获取 gps 位置的静态 map 图像

ios - 无法在 Android Studio 中为 Flutter 选择 iOS Phone Simulator

objective-c - 从 UITableView 获取 UITextField 文本

ios - 具有单行文本的 UILabel 的行间距

swift - NSAttributedString 在初始化时崩溃,但为什么呢?

iphone - 有条件地包含用于不同 iOS SDK 版本的库?

ios - 使用 Swift 动画 View 高度

ios - 如何减小行间距?

ios - NSAttributedString 对齐文本(不拉伸(stretch)单词)