UIImage 虚线框 可以用作 UITextfield、UIButton 的background,
2016-03-11 23:36
417 查看
1.方法一、
//size是背景图尺寸,border color是边框颜色,border width是边框大小。
extension UIImage {
class public
func getImageWithLineBroken(size:CGSize,borderColor:UIColor,borderWidth:CGFloat) ->
UIImage {
UIGraphicsBeginImageContextWithOptions(size,
false,
0.0);
UIColor.clearColor().set()
let context =
UIGraphicsGetCurrentContext();
CGContextBeginPath(context);
CGContextSetLineWidth(context, borderWidth);
CGContextSetStrokeColorWithColor(context, borderColor.CGColor);
let lengths:[CGFloat] = [3,
1];
CGContextSetLineDash(context,
0, lengths, 1);
// line 1
CGContextMoveToPoint(context,
30.0, 0.0);
CGContextAddLineToPoint(context,
170,
0.0);
// line 2
CGContextAddArcToPoint(context,
200 , 30, 170,
60, 30)
// line 3
//CGContextAddLineToPoint(context, 200, 30);
// line 4
CGContextAddLineToPoint(context,
170,
60);
CGContextAddLineToPoint(context,
30,
60);
CGContextAddArcToPoint(context,
0 , 30, 30,
0, 30)
CGContextAddLineToPoint(context,
30,
0);
// CGContextAddArc(context, 170, 30, 30, CGFloat(M_PI * 270/180), CGFloat(M_PI_2), 0)
// //CGContextMoveToPoint(context, 170, 60);
// CGContextAddLineToPoint(context, 30, 60);
//
// CGContextAddArc(context, 30, 30, 30, CGFloat(M_PI_2), CGFloat(M_PI * 270/180), 0)
// CGContextMoveToPoint(context, 170, 60);
CGContextStrokePath(context);
let image =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image
}
//size是背景图尺寸,border color是边框颜色,border width是边框大小。
extension UIImage {
class public
func getImageWithLineBroken(size:CGSize,borderColor:UIColor,borderWidth:CGFloat) ->
UIImage {
UIGraphicsBeginImageContextWithOptions(size,
false,
0.0);
UIColor.clearColor().set()
let context =
UIGraphicsGetCurrentContext();
CGContextBeginPath(context);
CGContextSetLineWidth(context, borderWidth);
CGContextSetStrokeColorWithColor(context, borderColor.CGColor);
let lengths:[CGFloat] = [3,
1];
CGContextSetLineDash(context,
0, lengths, 1);
// line 1
CGContextMoveToPoint(context,
30.0, 0.0);
CGContextAddLineToPoint(context,
170,
0.0);
// line 2
CGContextAddArcToPoint(context,
200 , 30, 170,
60, 30)
// line 3
//CGContextAddLineToPoint(context, 200, 30);
// line 4
CGContextAddLineToPoint(context,
170,
60);
CGContextAddLineToPoint(context,
30,
60);
CGContextAddArcToPoint(context,
0 , 30, 30,
0, 30)
CGContextAddLineToPoint(context,
30,
0);
// CGContextAddArc(context, 170, 30, 30, CGFloat(M_PI * 270/180), CGFloat(M_PI_2), 0)
// //CGContextMoveToPoint(context, 170, 60);
// CGContextAddLineToPoint(context, 30, 60);
//
// CGContextAddArc(context, 30, 30, 30, CGFloat(M_PI_2), CGFloat(M_PI * 270/180), 0)
// CGContextMoveToPoint(context, 170, 60);
CGContextStrokePath(context);
let image =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image
}
相关文章推荐
- NGUI DrawCall优化
- 用UIPickerView来显示省和市
- java continue 语句的应用
- HDFS之SequenceFile和MapFile
- UIPicker city.plist(实例)
- iOS开发基础 :UILabel属性
- UIScroll和UIPickView
- android的ui组件布局提示:android.widget.XXX cannot be cast to android.widget.YYY解决
- iiOS 开发基础:UIImageView属性
- iOS开发基础 :UIButton属性
- String ,Stringbuffer ,StringBuilder;
- Android子线程中更新UI的3种方法
- iOS开发--UIPickerView(选择器控件) 省份和城市的做法
- UINavigationController导航控制器
- 最新OSSIM改装平台DEMO WebUI
- bind 的第三方性能测试工具 queryperf
- UITableView和UICollectionView列表出现重叠问题
- iOS--UIAlertView与UIAlertController和UIAlertAction之间的事儿
- UIPickerView
- iOS UIPickerView 显示全国省市