< IOS开发 >使用CGContextRef绘制文字时的设置

时间:2015-07-01 22:03:51   收藏:0   阅读:340
        NSString *str = @"hello";
        //字体
        UIFont *font = [UIFont systemFontOfSize:16.0];
        //文本风格,设置居中
        NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
        [paragraphStyle setAlignment:NSTextAlignmentCenter];
        //文本位置
        CGRect iRect = CGRectMake(0, 0, 100, 20);
        //打印文本
        [str drawInRect:iRect withAttributes:@{NSFontAttributeName:font,NSParagraphStyleAttributeName:paragraphStyle}];

注意drawInRect:withAttributes函数在IOS7之后才能使用

原文:http://www.cnblogs.com/aY-Wonder/p/4614474.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!