就像在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];
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句