你怎么能在UILabel中只用一个词呢?

Gar*_*ran 8 iphone

显示完全相同文本的单个标签很容易,但是当您想要以粗体显示一个单词时会发生什么?

例:

你所有的基地属于我们.

Jer*_*man 7

UILabel本身无法在文本中绘制具有不同属性/字体的标签.但核心文本可以.您可以创建UILabel包装属性字符串的子类,并使用Core Text绘制它.您可以像Core Text编程指南中的示例代码一样处理绘图:

// 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);
Run Code Online (Sandbox Code Playgroud)