博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
通过 CALayer 代理方法绘图
阅读量:7286 次
发布时间:2019-06-30

本文共 1009 字,大约阅读时间需要 3 分钟。

#import "ViewController.h"#define WIDTH 50#define PHOTO_HEIGHT 150@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad{    [super viewDidLoad];    CALayer *layer=[CALayer layer];    layer.bounds=CGRectMake(0, 0, PHOTO_HEIGHT, PHOTO_HEIGHT);    layer.position=CGPointMake(160, 200);    layer.backgroundColor=[UIColor redColor].CGColor;    layer.cornerRadius=PHOTO_HEIGHT/2;    layer.masksToBounds=YES;        layer.borderColor=[UIColor whiteColor].CGColor;    layer.borderWidth=2;    layer.delegate=self;    [self.view.layer addSublayer:layer];    [layer setNeedsDisplay];                }-(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx{    CGContextSaveGState(ctx);    CGContextScaleCTM(ctx, 1, -1);    CGContextTranslateCTM(ctx, 0, -PHOTO_HEIGHT);    UIImage *image=[UIImage imageNamed:@"1"];    CGContextDrawImage(ctx, CGRectMake(0, 0, PHOTO_HEIGHT, PHOTO_HEIGHT), image.CGImage);    CGContextRestoreGState(ctx);}

转载于:https://www.cnblogs.com/thbbsky/p/4332385.html

你可能感兴趣的文章
xcode报错集锦_1
查看>>
hadoop-mapreduce分析
查看>>
多线程学习(4)wait/notify
查看>>
OSChina 周五乱弹——让人伤心的事
查看>>
Golang配置
查看>>
android下拉刷新
查看>>
linux 中route命令的使用
查看>>
ArrayList既然继承自AbstractList抽象类,而AbstractList已经实现了List接口,那么ArrayList类为何还要再实现List接口呢?...
查看>>
CentOS安装Redis
查看>>
在iOS上实现一个简单的日历控件
查看>>
Android——Type mismatch类型转换错误的根源
查看>>
4.Utm详细实现-用户资源管理
查看>>
CentOS7.3安装Python3.6
查看>>
怎么才能用ABBYY FineReader提高工作效率
查看>>
STORM 落入MONGO速度优化
查看>>
python:守护进程deamon
查看>>
coding项目怎样和其他人共享
查看>>
Android wifi 设置相关
查看>>
vue中一个关于input元素的小坑
查看>>
oracle避免约束带来的导入数据解决方案
查看>>