发布时间:2015-01-30 17:55 类别:IOS开发
/*
路径属于我们正在绘制他们的上下文。路径没有边界(Boundary)或特定的形状,不想我们使用路径绘制出来的形状。
但路径没有边界框(Bounding boxes). 此处,Boundary与Bounding boxes完全不一样。
边界显示你在画布上哪些不可以用来绘画,而路径的边界框是包含了所有路径的形状、点和其他已经绘制的对象的最小矩形。
使用路径创建步骤:创建路径的方法返回一个路径的句柄,可以在绘制图形的使用就可以把句柄作为传递给core Graphics。
当创建路径之后,可以向它添加不同的点、线条和形状,之后绘制图形。
1、CGPathCreateMutable 函数
创建一个CGMutablePathRef 的可变路径,并返回其句柄。
2、CGPathMoveToPoint 过程
在路径上移动当前画笔的位置到一个点,这个点由CGPoint 类型的参数指定。
3、CGPathAddLineToPoint 过程
从当前的画笔位置向指定位置(同样由CGPoint类型的值指定)绘制线段
4、CGContextAddPath 过程
添加一个由句柄指定的路径的图形上下文,准备用于绘图
5、CGContextDrawPath 过程
在图形上下文中绘制给出的路径。
6、CGPathRelease 过程
释放为路径句柄分配的内存。
7、CGPathAddRect 过程
向路径添加一个矩形。矩形的边界由一个CGRect 结构体指定。
*/
/*
*创建一个新的可变路径(CGPathCreateMutable),把该路径加到你的图形上下文(CGContextAddPath)
*并把它绘制到图形上下文中(CGContextDrawPath)
*/
具体代码:
学习记录// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
/*
*创建一个新的可变路径(CGPathCreateMutable),把该路径加到你的图形上下文(CGContextAddPath)
*并把它绘制到图形上下文中(CGContextDrawPath)
*/
/* Create the path */
CGMutablePathRef path = CGPathCreateMutable();
/* How big is our screen? We want the X to cover the whole screen */
CGRect screenBounds = [[UIScreen mainScreen] bounds];
/* Start from top-left */
CGPathMoveToPoint(path, NULL,screenBounds.origin.x, screenBounds.origin.y);
/* Draw a line from top-left to bottom-right of the screen */
CGPathAddLineToPoint(path, NULL,screenBounds.size.width, screenBounds.size.height);
/* Start another line from top-right */
CGPathMoveToPoint(path, NULL,screenBounds.size.width, screenBounds.origin.y);
/* Draw a line from top-right to bottom-left */
CGPathAddLineToPoint(path, NULL,screenBounds.origin.x, screenBounds.size.height);
/* Get the context that the path has to be drawn on */
CGContextRef currentContext = UIGraphicsGetCurrentContext();
/* Add the path to the context so we can draw it later */
CGContextAddPath(currentContext, path);
/* Set the blue color as the stroke color */
[[UIColor blueColor] setStroke];
/* Draw the path with stroke color */
CGContextDrawPath(currentContext, kCGPathStroke);
/* Finally release the path object */
CGPathRelease(path);
/*
*传入CGPathMoveToPoint等过程的NULL参数代表一个既定的变换,在给定的路径绘制线条时可以使用此变换。
*/
}
1
iOS7实现带文本输入框的UIAlertVi2
IOS开发调整UILabel的行间距3
sdwebimage如何获取缓存大小以及4
xcode6下使用autolayout+sizeclas5
ios app启动图片,之后的广告图片6
App store 发布,64位问题,Missi7
IOS 手势之左右滑动UISwipeGestur8
H5页面如何唤醒app9
didRegisterForRemoteNotificatio10
ios中实现多行输入的UITextField11
ios 点击网页页面判断是否安装app12
iOS UIScrollView的边界处理问题13
IOS SDK百度地图不能正常显示,只14
IOS 去掉uibutton点击高亮无效15
ios label设置行高间距16
ios 图形与动画学习笔记 构造路径17
CUICatalog: Invalid asset name18
使用 NSUserDefaults 读取和写入19
UIRefreshControl使用描述与实现20
uitableview处理section的不悬浮21
ASIHTTPRequest中的DELETE、PUT、22
IOS8下,百度地图无法定位解决办23
iOS 的UITextField如何检测退格键24
如何创建CGColorRef在view.layer.25
UITextField、UITextView 键盘遮26
ios 判断字符串为空和只为空格解27
process launch failed: timed ou28
ios webview清除缓存Cookie29
IOS Object-c学习之设计类接口与30
UITableView headerViewForSectioCopyright © 2015 www.wahenzan.com 哇!很赞 版权所有 浙ICP备14030256号-1 Power by DedeCms
声明:本站所有文章除标明原创外,均来自网络转载,版权归原作者所有,如果有侵犯到您的权益,请联系本站删除 网站管理员:758763728