ios - 如何将 UILabel 绘制到上下文中
<p><p>我正在尝试将 UIlabel 绘制到特定位置的新上下文中。我知道您可以轻松地将 NSString 绘制到上下文中,但我想保留 UILabel 的文本大小、颜色和自动换行样式。感谢您的帮助!</p>
<pre><code> UIGraphicsBeginImageContext(targetSize);
// here is where I want to draw UILabel to context
UIGraphicsEndImageContext();
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>你可以画<em>任何</em> View <a href="https://stackoverflow.com/questions/788662/rendering-uiview-with-its-children-iphone-sdk" rel="noreferrer noopener nofollow">using <code>-renderInContext:</code></a> ,但如果您只需要保留文本大小、颜色和自动换行样式,您可以简单地 <a href="http://developer.apple.com/library/ios/documentation/UIKit/Reference/NSString_UIKit_Additions/Reference/Reference.html#//apple_ref/occ/instm/NSString/drawInRect:withFont:lineBreakMode:alignment:" rel="noreferrer noopener nofollow">use <code>-drawInRect:withFont:lineBreakMode:alignment:</code></a>自定义所有选项。</p>
<pre><code>;
[label.text drawInRect:label.bounds
withFont:label.font
lineBreakMode:label.lineBreakMode
alignment:label.textAlignment];
</code></pre>
<p>还有<a href="http://developer.apple.com/library/ios/documentation/UIKit/Reference/UILabel_Class/Reference/UILabel.html#//apple_ref/occ/instm/UILabel/drawTextInRect:" rel="noreferrer noopener nofollow">a <code>-drawTextInRect:</code> method</a>在 UILabel 中,但 Apple 说 <em>“你不应该直接调用这个方法。”</em> </p></p>
<p style="font-size: 20px;">关于ios - 如何将 UILabel 绘制到上下文中,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/5929835/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/5929835/
</a>
</p>
页:
[1]