当前位置

网站首页> 程序设计 > 开源项目 > 程序开发 > 浏览文章

IOS-绘制2D图形

作者:小梦 来源: 网络 时间: 2024-06-04 阅读:
@implementation MyView- (void)drawRect:(CGRect)rect {        UIBezierPath  * path=[[UIBezierPath  alloc]init];    [[UIColor  brownColor]setStroke];//设置绘图上下文的颜色。上下文在一个进程内部是单例的,所以可以设置。在setStroke内部会取得当前绘图上下文。   [path  moveToPoint:CGPointMake(0, 0)];   [path  addLineToPoint:CGPointMake(50, 50)];    [path  moveToPoint:CGPointMake(50, 0)];    [path  addLineToPoint:CGPointMake(100, 100)];    [path   stroke];//表示绘制图形    //上面其实是绘制了两条线}@end
#import "ViewController.h"#import "MyView.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.    CGRect   frame=CGRectMake(20, 20, 100, 100);        UIView*   view= [[MyView alloc]initWithFrame:frame];        [self.view addSubview:view];}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end

热点阅读

网友最爱