gpt4 book ai didi

ios - 如何在 UITextView 中绘制文本

转载 作者:行者123 更新时间:2023-11-28 21:50:16 25 4
gpt4 key购买 nike

如何在 UITextView 中绘制文本,就像 UILabel 和 UITextField 中有一个名为“drawTextInRect:”的方法一样。我应该在“drawRect:”或“drawLayer:inContext:”中实现它吗?感谢您的专注和耐心!

最佳答案

您可以像下面的代码一样使用 drawinrect。

UIFont *font = [UIFont fontWithName:@"Courier" size:kCellFontSize];

/// Make a copy of the default paragraph style
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
/// Set line break mode
paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;
/// Set text alignment
paragraphStyle.alignment = NSTextAlignmentRight;

NSDictionary *attributes = @{ NSFontAttributeName: font,
NSParagraphStyleAttributeName: paragraphStyle };

[text drawInRect:rect withAttributes:attributes];

关于ios - 如何在 UITextView 中绘制文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28597216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com