代码画的
UITextField *entryReason = [[UITextField alloc] init];
[_popView addSubview:entryReason];
[entryReason zxp_addConstraints:^(ZXPAutoLayoutMaker *layout) {
layout.topSpaceByView(defeatReason,11);
layout.leftSpace(20);
layout.rightSpace(20);
layout.heightValue(30);
}];
entryReason.borderStyle = UITextBorderStyleNone;
entryReason.layer.borderWidth = 0;
entryReason.placeholder = @"申请理由";
// 设置虚线背景
entryReason.background = [UIImage imageWithSize:CGSizeMake(250, 30) borderColor:[UIColor grayColor] borderWidth:1];
效果图
UIImage的分类
//添加虚线
+ (UIImage*)imageWithSize:(CGSize)size borderColor:(UIColor *)color borderWidth:(CGFloat)borderWidth
{
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
[[UIColor clearColor] set];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextBeginPath(context);
CGContextSetLineWidth(context, borderWidth);
CGContextSetStrokeColorWithColor(context, color.CGColor);
CGFloat lengths[] = { 3, 1 };
CGContextSetLineDash(context, 0, lengths, 1);
CGContextMoveToPoint(context, 0.0, 0.0);
CGContextAddLineToPoint(context, size.width, 0.0);
CGContextAddLineToPoint(context, size.width, size.height);
CGContextAddLineToPoint(context, 0, size.height);
CGContextAddLineToPoint(context, 0.0, 0.0);
CGContextStrokePath(context);
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
网友评论