iOS小明开发笔记(十三) (Quartz2D简单使用二)

一、画文字

#import "MMTextView.h"

 @implementation MMTextView


 - (void)drawRect:(CGRect)rect

 {

    

         // 画文字

         NSString *str = @"的额搜风搜分手了粉色发俄双方说法offFF瓦房你F回复F入会费WFH;飞;FN返回WFH;哦发货;F回复;FHISFHSIFH我皮肤好APIFRHi分红AWFHIOF威锋网i";

         // 1.获取上下文

         //    CGContextRef ctx = UIGraphicsGetCurrentContext();

         // 2.绘图

         // 不推荐使用C语言的方法绘制文字因为quraz2d中的坐标系和UIkit中的坐标系不一致绘制出来的文字是颠倒的而且通过C语言的方法绘制文字相当麻烦

         //    CGContextSelectFont(<#CGContextRef c#>, <#const char *name#>, <#CGFloat size#>, <#CGTextEncoding textEncoding#>)

         //    CGContextShowText(ctx, <#const char *string#>, <#size_t length#>)

    

         // 绘制矩形

         // 1.获取上下文

         CGContextRef ctx = UIGraphicsGetCurrentContext();

         // 2.绘图

         CGContextAddRect(ctx, CGRectMake(5050100100));

         // 3.渲染

         CGContextStrokePath(ctx);

    

         //    NSMutableDictionary *md = [NSMutableDictionary dictionary];

         // 设置文字颜色

         //    md[NSForegroundColorAttributeName] =[UIColor redColor];

         // 设置文字背景颜色

         //    md[NSBackgroundColorAttributeName] = [UIColor greenColor];

         // 设置文字大小

         //    md[NSFontAttributeName] = [UIFont systemFontOfSize:20];

         //    将文字绘制到指点的位置

         //    [str drawAtPoint:CGPointMake(10, 10) withAttributes:md];

         //    将文字绘制到指定的范围内如果一行装不下会自动换行当文字超出范围后就不显示

         [str drawInRect:CGRectMake(5050100100) withAttributes:nil];

     }

 @end

图片

二、图片
(1、) 

#import "MMImage.h"


 @implementation MMImage


- (void)drawRect:(CGRect)rect

 {

         //    1.加载图片到内存中

         UIImage *image = [UIImage imageNamed:@"me"];

         // 利用drawAsPatternInRec方法绘制图片到layer, 是通过平铺原有图片

         [image drawAsPatternInRect:CGRectMake(00320480)];

     }

 @end

效果(平铺):

图片
(2、) 
 
#import "MMImage.h"


@implementation MMImage


 - (void)drawRect:(CGRect)rect

 {

         //    1.加载图片到内存中

         UIImage *image = [UIImage imageNamed:@"me"];

         // 利用OC方法将图片绘制到layer

         // 利用drawInRect方法绘制图片到layer, 是通过拉伸原有图片

         [image drawInRect:CGRectMake(00200200)];

         // 利用drawAsPatternInRec方法绘制图片到layer, 是通过平铺原有图片

     //    [image drawAsPatternInRect:CGRectMake(0, 0, 320, 480)];

     }

 @end

图片
(3、) 

#import "MMImage.h"


@implementation MMImage


- (void)drawRect:(CGRect)rect

    {

         //    1.加载图片到内存中

         UIImage *image = [UIImage imageNamed:@"me"];

         // 利用OC方法将图片绘制到layer

         // 将图片绘制到指定的位置

         [image drawAtPoint:CGPointMake(100100)];

}

图片

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值