首页 > 其他 > 详细

4. Quartz2D 绘制文字

时间:2015-02-17 12:46:22      阅读:284      评论:0      收藏:0      [点我收藏+]
#pragma mark 绘制文字(中文)
-(void)drawText2:(CGContextRef)context{
    NSString *string = @"博阿士大夫撒风景撒开了房间撒";
    //1.获取字体
    NSLog(@"%@",[UIFont familyNames]);
    UIFont *font = [UIFont fontWithName:@"Marker Felt" size:20];
    //如果在UILabel中,可以将numbersOfLine设置0,并且指定足够的高度即可
    
    CGRect rect = CGRectMake(290, 10, 30, 440);
    [[UIColor lightGrayColor]set];
    UIRectFrame(rect);
    
    [[UIColor redColor]set];
    
    /*
     提示:在对齐方式的枚举中
     a. NSTextAlignmentJustified两端对齐
     b. NSTextAlignmentNatural
     以上两种对其方式不能使用
     */
    [string drawInRect:rect withFont:font lineBreakMode:(NSLineBreakByCharWrapping) alignment:(NSTextAlignmentLeft) ];
    
}


#pragma mark 绘制文字(英文)
-(void)drawText:(CGContextRef)context{
    NSString *string = @"Hello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello world";
    //1.获取字体
    NSLog(@"%@",[UIFont familyNames]);
    UIFont *font = [UIFont fontWithName:@"Marker Felt" size:40];
    //在指定点绘制字符串
    [string drawAtPoint:CGPointMake(50, 50) withFont:font];
    //如果在UILabel中,可以将numbersOfLine设置0,并且指定足够的高度即可
    
    CGRect rect = CGRectMake(50, 50, 270, 360);
    [[UIColor lightGrayColor]set];
    UIRectFrame(rect);
    
    [[UIColor redColor]set];
    
    /*
     提示:在对齐方式的枚举中
        a. NSTextAlignmentJustified两端对齐
        b. NSTextAlignmentNatural
     以上两种对其方式不能使用
     */
    [string drawInRect:rect withFont:font lineBreakMode:(NSLineBreakByWordWrapping) alignment:(NSTextAlignmentLeft) ];
    
}

 

4. Quartz2D 绘制文字

原文:http://www.cnblogs.com/wlxm/p/4295126.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!