ios - 如何使用核心文本在ios中的不同UIlabel文本行上设置不同的字体样式

标签 ios objective-c swift uilabel core-text

我想使标签格式线成为不同大小的标签文本字的动态形状如何使用核心文本框架

请在Dynamic arrange label text上的动态形状生成上显示此类型格式Diffent font style arrange

请建议使用 coustom 库来制作此类型格式

最佳答案

我只是用 NSAttributedString 向您展示方向,您必须弄清楚其余的细节,例如正确的字体、大小、样式、行间距等。(提示:检查 NSMutableParagraphStyle)

    let attr = NSMutableAttributedString(string: "")
    attr.appendAttributedString(NSAttributedString(string: "The\n", attributes: [NSFontAttributeName: UIFont.boldSystemFontOfSize(60), NSForegroundColorAttributeName: UIColor.greenColor()]))
    attr.appendAttributedString(NSAttributedString(string: "HAPPINESS OF\n", attributes: [NSFontAttributeName: UIFont.systemFontOfSize(45), NSForegroundColorAttributeName: UIColor.redColor()]))
    attr.appendAttributedString(NSAttributedString(string: "YOUR LIFE\n", attributes: [NSFontAttributeName: UIFont.italicSystemFontOfSize(40), NSForegroundColorAttributeName: UIColor.purpleColor()]))
    attr.appendAttributedString(NSAttributedString(string: "DEPENDS UPON", attributes: [NSFontAttributeName: UIFont.boldSystemFontOfSize(15), NSForegroundColorAttributeName: UIColor.brownColor()]))
    label.attributedText = attr

enter image description here

关于ios - 如何使用核心文本在ios中的不同UIlabel文本行上设置不同的字体样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38388667/

相关文章:

ios - 什么时候调用 ViewWillLayoutSubviews 和 ViewDidLayoutSubviews 方法?

ios - MPMedia 查询过滤播放列表中的歌曲不起作用

xcode - 如何设置canBecomeKeyWindow?

ios - Swift:无法正确访问 JSON 代码。 (打开包装时发现为零)

ios - 从错误 : "Receiver has no segue with identifier" 启动 segue

ios - 在 NSBundle 中加载自定义 NSBundle

ios - dyld`__abort_with_payload : Without an error message

ios - 试图防止内存泄漏

ios - UIView 上的平滑帧动画

objective-c - 在 UITableviewCell 高度动画的同时动画 CALayer 阴影