#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) ];
}