[英]How to draw text in UITextView
就像在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];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.