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

来源:互联网 发布:手机音乐合并软件 编辑:程序博客网 时间:2024/05/23 17:34
画一个小原点的代码----------------------    UIGraphicsBeginImageContext(CGSizeMake(150, 150));//创建位图上下文    CGContextRef ctx = UIGraphicsGetCurrentContext();//返回当前上下文    CGContextBeginPath(ctx);//创建新路径    CGContextAddArc(ctx, 10,10, 10, 0, 4*M_PI, 1);//使用狐制度创建狐    CGContextSetRGBFillColor(ctx, 1, 0, 0, 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, 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];

原创粉丝点击