就像在UILabel和UITextField中有一种称为“ drawTextInRect:”的方法一样,如何在UITextView中绘制文本。我应该在“ 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/