显示具有完全相同文本的单个标签很容易,但是当您想以粗体显示一个单词时会发生什么?
Example:
你所有的基地are属于我们。
UILabel
本身无法在文本中绘制具有不同属性/字体的标签。但核心文本可以。您可以创建一个子类UILabel
它包装一个属性字符串并使用 Core Text 来绘制它。您可以像这样处理绘图这个示例代码 http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/CoreText_Programming/Operations/Operations.html#//apple_ref/doc/uid/TP40005533-CH4-SW18来自核心文本编程指南:
// Build up your attributed string, then...
CTLineRef line = CTLineCreateWithAttributedString(attrString);
// Set text position and draw the line into the graphics context
CGContextSetTextPosition(context, 10.0, 10.0);
CTLineDraw(line, context);
CFRelease(line);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)