2011-06-26 19 views
3

私は、カスタムテキストを描画しています:drawAtPointで複数行のテキストを描画するにはどうすればよいですか?

point = CGPointMake(77, 5); 
    [[message valueForKey:@"user_login"] drawAtPoint:point forWidth:200 
              withFont:mainFont 
             minFontSize:MIN_MAIN_FONT_SIZE 
             actualFontSize:NULL 
             lineBreakMode:UILineBreakModeTailTruncation 
            baselineAdjustment:UIBaselineAdjustmentAlignBaselines]; 

は、どのように私はそれが5線を引くことができますか?相当:

rect = CGRectMake(77, 25, 238, 68); 
bodyLabel = [[UILabel alloc] initWithFrame:rect]; 
bodyLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:12]; 
bodyLabel.numberOfLines = 5; 
bodyLabel.lineBreakMode = UILineBreakModeWordWrap; 
    bodyLabel.textColor = [UIColor blackColor]; 
    [self.contentView addSubview: bodyLabel]; 

答えて

6

-drawAtPoint:withFont:...のドキュメントには、「このメソッドは、描画時に任意の行の折り返しを行いません。」と言います-drawAtPoint:withFont:...の代わりに-drawInRect:withFont:を使用すると、複数の行が描画されます。また、-sizeWithFont:constrainedToSize:を使って、サイズを調べることもできます。

0

の代わりにあなたがdrawWithRect:options:attributes:context:

[string drawWithRect:CGRectMake(x, y, width, height) 
      options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine 
      attributes:@{NSFontAttributeName:<font>, NSForegroundColorAttributeName:<color> 
      context:nil]; 
を使用する必要がありますiOS7 +で drawInRect:withFont:...を非推奨
関連する問題