UIView 周围的虚线边框 [英] Dashed line border around UIView
本文介绍了UIView 周围的虚线边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 UIView
周围添加虚线边框.
How do I add dashed line border around UIView
.
类似的东西
推荐答案
您可以使用图层和贝塞尔路径(如下例所示)使用此模式设置边框.
You can set the border with this pattern using Layer and Bezier path like below examples.
目标 C
CAShapeLayer *yourViewBorder = [CAShapeLayer layer];
yourViewBorder.strokeColor = [UIColor blackColor].CGColor;
yourViewBorder.fillColor = nil;
yourViewBorder.lineDashPattern = @[@2, @2];
yourViewBorder.frame = yourView.bounds;
yourViewBorder.path = [UIBezierPath bezierPathWithRect:yourView.bounds].CGPath;
[yourView.layer addSublayer:yourViewBorder];
Swift 3.1
var yourViewBorder = CAShapeLayer()
yourViewBorder.strokeColor = UIColor.black.cgColor
yourViewBorder.lineDashPattern = [2, 2]
yourViewBorder.frame = yourView.bounds
yourViewBorder.fillColor = nil
yourViewBorder.path = UIBezierPath(rect: yourView.bounds).cgPath
yourView.layer.addSublayer(yourViewBorder)
您还可以使用图案图像设置不同类型的设计,如下例所示.
You can also set different types of design using pattern image like below example.
[yourView.layer setBorderWidth:5.0];
[yourView.layer setBorderColor:[[UIColor colorWithPatternImage:[UIImage imageNamed:@"DotedImage.png"]] CGColor]];///just add image name and create image with dashed or doted drawing and add here
在这里,您必须在项目中添加
框架,并在 YourViewController.m
文件中使用以下行将其导入.
Here you've to add <QuartzCore/QuartzCore>
framework in the project and import it with below line in YourViewController.m
file.
#import <QuartzCore/QuartzCore.h>
这篇关于UIView 周围的虚线边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文