cocoa touch layer下面的几个点连载之--CoreGraphics

cocoa touch layer下面的几个点连载之--CoreGraphics,第1张

概述画一个小原点的代码---------------------- UIGraphicsBeginImageContext(CGSizeMake(150, 150));//创建位图上下文 CGContextRef ctx = UIGraphicsGetCurrentContext();//返回当前上下文 CGContextBeginPath(ctx);//创建新路径
画一个小原点的代码----------------------    UIGraphicsBeginImageContext(CGSizeMake(150,150));//创建位图上下文    CGContextRef ctx = UIGraphicsGetCurrentContext();//返回当前上下文    CGContextBeginPath(ctx);//创建新路径    CGContextAddArc(ctx,10,4*M_PI,1);//使用狐制度创建狐    CGContextSetRGBFillcolor(ctx,1,1);//设置颜色    CGContextFillPath(ctx);//自动关闭路径,并通过填充对路径进行喷漆.       UIImage *redball = UIGraphicsGetimageFromCurrentimageContext();//返回一个位图上下文,仅仅用于位图    UIGraphicsEndImageContext();//关闭位图上下文       UIImageVIEw *redballvIEw = [[UIImageVIEw alloc]initWithImage:redball];    redballvIEw.center = CGPointMake(200,300);    [self.vIEw addSubvIEw:redballvIEw];-----------------------------------------CGContextAddArc是一个比较强大的函数CGContextAddArc(CGContextRef c,CGfloat x,CGfloat y,CGfloat radius,CGfloat startAngle,CGfloat endAngle,intclockwise)CGContextRef: 图形上下文x,y: 开始画的坐标radius: 半径startAngle,endAngle: 开始的弧度,结束的弧度clockwise: 画的方向(顺时针,逆时针)先要好好理解下上面那个函数,这个在上面的代码总来说是最难理解的,如果english nx可能就另当别论了.无意中找到一个很叼的学习参考网站,放着记下http://objective-j.org/learn/documentation/group__coregraphics.HTML#gac3f1c96dd9247e1ebc30d89b1b2acf13在iPhone屏幕上画长方形,直线和文字画扇形和画方形、画直线完全是两码事儿, //画长方形CGContextRef ctx = UIGraphicsGetCurrentContext();//设置颜色,仅填充4条边CGContextSetstrokecolorWithcolor(ctx,[[UIcolor colorWithRed:1 green:1 blue:1 Alpha:0.5] CGcolor]);//设置线宽为1 CGContextSetlinewidth(ctx,1.0);//设置长方形4个顶点CGPoint poins[] = {CGPointMake(5,5),CGPointMake(425,125),CGPointMake(5,125)};CGContextAddlines(ctx,poins,4);CGContextClosePath(ctx);CGContextstrokePath(ctx); //画直线,x1和y1是起始点,x2和y2是结束点//默认坐标系左上角为0,0CGContextMovetoPoint(ctx,x1,y1);CGContextAddlinetoPoint(ctx,x2,y2);CGContextClosePath(ctx);CGContextstrokePath(ctx); //画文字,设置文字内容Nsstring *text = @"text";//设置字体大小UIFont *Font = [UIFont systemFontOfSize:8];//在指定x,y点位置画文字,宽度为18[text drawAtPoint:CGPointMake(x,y) forWIDth:18 withFont:FontminFontSize:8 actualFontSize:NulLlineBreakMode:UIlineBreakModeTailTruncationbaselineAdjustment:UIBaselineAdjustmentAlignBaselines];[text release];
总结

以上是内存溢出为你收集整理的cocoa touch layer下面的几个点连载之--CoreGraphics全部内容,希望文章能够帮你解决cocoa touch layer下面的几个点连载之--CoreGraphics所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1059152.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存