码迷,mamicode.com
首页 > Windows程序 > 详细

drawInRect:withAttributes:

时间:2015-01-25 12:30:17      阅读:352      评论:0      收藏:0      [点我收藏+]

标签:

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

drawInRect:withAttributes:

标签:

原文地址:http://www.cnblogs.com/yangmx/p/4247960.html

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