iPhone – How to draw multi-line text using DrawatPoint?

I am custom drawing some text:

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

How do I draw 5 lines? Equivalent to:

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];

-drawAtPoint’s document: withFont: …Said “This method does not perform any line breaks during drawing”. If you use -drawInRect:withFont: instead of -drawAtPoint:withFont:…, then it will draw multiple lines. You can also use -sizeWithFont:constrainedToSize: to determine the size .

I am custom drawing some text:

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];

How do I draw 5 lines? Equivalent to:

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];

-drawAtPoint’s documentation: withFont: … says “This method does not perform any line breaks during drawing “. If you use -drawInRect:withFont: instead of -drawAtPoint:withFont:…, then it will draw multiple lines. You can also use -sizeWithFont:constrainedToSize: to determine the size.

Leave a Comment

Your email address will not be published.