码迷,mamicode.com
首页 > 移动开发 > 详细

ios-drawInRect:withAttributes

时间:2016-04-18 16:56:46      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

http://stackoverflow.com/questions/19274408/drawinrectwithattributes-vs-drawinrectwithfontlinebreakmodealignment
- (void)drawRect:(CGRect)frame
{
NSMutableParagraphStyle *textStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
textStyle.lineBreakMode = NSLineBreakByWordWrapping;
textStyle.alignment = NSTextAlignmentCenter;
UIFont *textFont = [UIFont systemFontOfSize:16];

NSString *text = @"Lorem ipsum";

// iOS 7 way
[text drawInRect:frame withAttributes:@{NSFontAttributeName:textFont, NSParagraphStyleAttributeName:textStyle}];

// pre iOS 7 way
CGFloat margin = 16;
CGRect bottomFrame = CGRectMake(0, margin, frame.size.width, frame.size.height - margin);
[text drawInRect:bottomFrame withFont:textFont lineBreakMode:NSLineBreakByWordWrapping alignment:NSTextAlignmentCenter];
}

ios-drawInRect:withAttributes

标签:

原文地址:http://www.cnblogs.com/qike/p/5404944.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!