【问题标题】:How to draw text in UITextView如何在 UITextView 中绘制文本
【发布时间】:2015-02-19 01:28:55
【问题描述】:

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

【问题讨论】:

    标签: ios objective-c uiview drawing uitextview


    【解决方案1】:

    你可以像下面的代码一样使用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];
    

    【讨论】:

      猜你喜欢
      • 2011-10-28
      • 1970-01-01
      • 1970-01-01
      • 2012-03-05
      • 2012-02-14
      • 1970-01-01
      • 2014-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多