swift画圆角对话框
2016-05-26 18:57
363 查看
这里的圆角的对话框 我指的是类似安卓的.9.png那样的圆角的对话框,就是这个样子的。
分解出来就是一个实心的圆角矩形加一个三角形,外面用直线描边,里面写一些居中悬浮的字符串而已。
1.画圆角矩形 假设x1,y1为右下角的点
let rx:CGFloat =
4 //圆角弧度
CGContextSetFillColorWithColor(context,
UIColor(red: 248/255, green:
248/255, blue:
248/255, alpha:1).CGColor)
//设置画笔颜色
CGContextMoveToPoint(context, x1, y1 - rx); // 右下角
CGContextAddArcToPoint(context, x1, y1, x2, y1, rx);
// 右下角度-左下角
CGContextAddArcToPoint(context, x2, y1, x2, y2, rx);
// 左下角-左上角
CGContextAddArcToPoint(context, x2, y2, x1, y2, rx); //
左上角-右上角
CGContextAddArcToPoint(context, x1, y2, x1, y1, rx); //
右上角-右下脚
CGContextClosePath(context);//封起来
CGContextDrawPath(context, CGPathDrawingMode.Fill) //根据坐标绘制路径
2.画三角形
取圆角矩形的底边上某个点(xs,y1),这里随便举个栗子啦 这里x2<xs<x1
let sPoint = [CGPointMake(xs, y1),CGPointMake(xs + 10, y1),CGPointMake(xs + 5, y1+5)];
CGContextAddLines(context, sPoints5,
3);//添加线
CGContextClosePath(context);//封起来
CGContextDrawPath(context, CGPathDrawingMode.Fill)//根据坐标绘制路径
这样基本轮廓就出来啦,一个尖尖向下的对话框
3.描边
就是画线咯,注意在三角形区域不要画错喔
CGContextSetLineWidth(context, 0.5)
//设置画笔宽度
CGContextSetStrokeColorWithColor(context,
UIColor(red: 204/255, green:
204/255, blue:
204/255, alpha:1).CGColor)
//设置画笔颜色
CGContextMoveToPoint(context, x1, y1); //起点
CGContextAddLineToPoint(context, xs+10,
y1);
CGContextAddLineToPoint(context, xs+5,
y1+5); //斜边1
CGContextAddLineToPoint(context, xs, y1);
//斜边2
CGContextAddLineToPoint(context, x2, y1);
CGContextAddLineToPoint(context, x2, y2);
CGContextAddLineToPoint(context, x1, y2);
CGContextAddLineToPoint(context, x1,
y1);
CGContextStrokePath(context) //关闭路径
写到这里,萌萌哒圆角对话框就写好咯,加下来在里面挖坑写字符串就可以了
分解出来就是一个实心的圆角矩形加一个三角形,外面用直线描边,里面写一些居中悬浮的字符串而已。
1.画圆角矩形 假设x1,y1为右下角的点
let rx:CGFloat =
4 //圆角弧度
CGContextSetFillColorWithColor(context,
UIColor(red: 248/255, green:
248/255, blue:
248/255, alpha:1).CGColor)
//设置画笔颜色
CGContextMoveToPoint(context, x1, y1 - rx); // 右下角
CGContextAddArcToPoint(context, x1, y1, x2, y1, rx);
// 右下角度-左下角
CGContextAddArcToPoint(context, x2, y1, x2, y2, rx);
// 左下角-左上角
CGContextAddArcToPoint(context, x2, y2, x1, y2, rx); //
左上角-右上角
CGContextAddArcToPoint(context, x1, y2, x1, y1, rx); //
右上角-右下脚
CGContextClosePath(context);//封起来
CGContextDrawPath(context, CGPathDrawingMode.Fill) //根据坐标绘制路径
2.画三角形
取圆角矩形的底边上某个点(xs,y1),这里随便举个栗子啦 这里x2<xs<x1
let sPoint = [CGPointMake(xs, y1),CGPointMake(xs + 10, y1),CGPointMake(xs + 5, y1+5)];
CGContextAddLines(context, sPoints5,
3);//添加线
CGContextClosePath(context);//封起来
CGContextDrawPath(context, CGPathDrawingMode.Fill)//根据坐标绘制路径
这样基本轮廓就出来啦,一个尖尖向下的对话框
3.描边
就是画线咯,注意在三角形区域不要画错喔
CGContextSetLineWidth(context, 0.5)
//设置画笔宽度
CGContextSetStrokeColorWithColor(context,
UIColor(red: 204/255, green:
204/255, blue:
204/255, alpha:1).CGColor)
//设置画笔颜色
CGContextMoveToPoint(context, x1, y1); //起点
CGContextAddLineToPoint(context, xs+10,
y1);
CGContextAddLineToPoint(context, xs+5,
y1+5); //斜边1
CGContextAddLineToPoint(context, xs, y1);
//斜边2
CGContextAddLineToPoint(context, x2, y1);
CGContextAddLineToPoint(context, x2, y2);
CGContextAddLineToPoint(context, x1, y2);
CGContextAddLineToPoint(context, x1,
y1);
CGContextStrokePath(context) //关闭路径
写到这里,萌萌哒圆角对话框就写好咯,加下来在里面挖坑写字符串就可以了
相关文章推荐
- Swift可选链
- swift基础之错误异常
- swift画图
- 单例在Swift中的正确实现方式
- 在Swift怎样创建CocoaPod
- swift C风格语句被弃用,在未来将被删除
- Swift强制解析
- OC中通过Class动态添加一个控制器,Swift中怎么实现?
- Swift资源库--官方文档的学习笔记
- tableview线条距屏幕的距离
- 【swift学习笔记】二.页面转跳数据回传
- 【swift学习笔记】二.页面转跳数据回传
- Swift资源包----Swift语言的特点
- Swift\本地文件管理
- 证书过期:The certificate used to sign "###"...
- 11.swift 单例
- Swift资源包---OC和swift混合开发
- Swift 遍历数组元素
- Swift资源包--Sort方法
- swift基础笔记7-继承