自定义划线方法
2015-12-06 21:24
288 查看
#import "DrawLine.h"
@implementation DrawLine
+ (void)drawCenter:(UIImageView *)imageView withBeginX:(CGFloat)Bx withBeginY:(CGFloat)By withEndX:(CGFloat)Ex withEndY:(CGFloat)Ey withLineWidth:(CGFloat)width withColorR:(CGFloat)r
G:(CGFloat)g B:(CGFloat)b Alpha:(CGFloat)a
{
UIGraphicsBeginImageContext(imageView.frame.size);
[imageView.image drawInRect:CGRectMake(0,
0, imageView.frame.size.width, imageView.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), width);
//线宽
CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(),
YES);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), r, g, b, a);
//颜色
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), Bx, By);
//起点坐标
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), Ex, Ey);
//终点坐标
CGContextStrokePath(UIGraphicsGetCurrentContext());
imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
+ (void)drawLineCenter:(UIView *)view withBeginX:(CGFloat)Bx withBeginY:(CGFloat)By withEndX:(CGFloat)Ex withEndY:(CGFloat)Ey withLineWidth:(CGFloat)width withColorR:(CGFloat)r G:(CGFloat)g
B:(CGFloat)b Alpha:(CGFloat)a
{
UIImageView *imageView=[[UIImageView alloc] initWithFrame:view.frame];
imageView.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y,
500, view.frame.size.height);
[view addSubview:imageView];
view.backgroundColor = [UIColor clearColor];
UIGraphicsBeginImageContext(imageView.frame.size);
[imageView.image drawInRect:CGRectMake(0,
0, imageView.frame.size.width, imageView.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), width);
//线宽
CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(),
YES);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), r, g, b, a);
//颜色
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), Bx, By);
//起点坐标
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), Ex, Ey);
//终点坐标
CGContextStrokePath(UIGraphicsGetCurrentContext());
imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
@implementation DrawLine
+ (void)drawCenter:(UIImageView *)imageView withBeginX:(CGFloat)Bx withBeginY:(CGFloat)By withEndX:(CGFloat)Ex withEndY:(CGFloat)Ey withLineWidth:(CGFloat)width withColorR:(CGFloat)r
G:(CGFloat)g B:(CGFloat)b Alpha:(CGFloat)a
{
UIGraphicsBeginImageContext(imageView.frame.size);
[imageView.image drawInRect:CGRectMake(0,
0, imageView.frame.size.width, imageView.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), width);
//线宽
CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(),
YES);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), r, g, b, a);
//颜色
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), Bx, By);
//起点坐标
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), Ex, Ey);
//终点坐标
CGContextStrokePath(UIGraphicsGetCurrentContext());
imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
+ (void)drawLineCenter:(UIView *)view withBeginX:(CGFloat)Bx withBeginY:(CGFloat)By withEndX:(CGFloat)Ex withEndY:(CGFloat)Ey withLineWidth:(CGFloat)width withColorR:(CGFloat)r G:(CGFloat)g
B:(CGFloat)b Alpha:(CGFloat)a
{
UIImageView *imageView=[[UIImageView alloc] initWithFrame:view.frame];
imageView.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y,
500, view.frame.size.height);
[view addSubview:imageView];
view.backgroundColor = [UIColor clearColor];
UIGraphicsBeginImageContext(imageView.frame.size);
[imageView.image drawInRect:CGRectMake(0,
0, imageView.frame.size.width, imageView.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), width);
//线宽
CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(),
YES);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), r, g, b, a);
//颜色
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), Bx, By);
//起点坐标
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), Ex, Ey);
//终点坐标
CGContextStrokePath(UIGraphicsGetCurrentContext());
imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
相关文章推荐
- iOS:友盟SDK分享
- 信息安全系统设计基础第十三周学习总结——20135308
- 优秀开发地址 (包含前段,android 性能优化 以及react native)
- 图像处理领域的大牛
- linux下 lvm 磁盘扩容
- Spring mvc
- 如何在eclipse上使用egit插件
- Spring Boot自定义错误页面,Whitelabel Error Page处理方式
- properties类
- Android Studio的更新
- 产生冠军2094
- 我的序——科学与人文
- LeetCode 之 Reverse Integer
- Linux LVM硬盘管理及LVM扩容
- Python小爬虫练习
- 3 决策树(一)
- 20135231 —— 第十二周任务总结报告
- 复杂度问题
- java字符串传值问题
- 1048. Find Coins (25)【排序】——PAT (Advanced Level) Practise