草庐IT

uibezierpath

全部标签

ios - 使用 UIBezierPath 屏蔽 UIView - 仅描边

更新02有一个可行的解决方案...我正在尝试将UIBezierPath的描边用作另一个UIView上的mask。例子很多,但都是用fill来裁剪View。我试图只使用路径的笔触,但它显示不正确。下面是我目前在Swift3.x中的内容:letbezierPath=UIBezierPath()bezierPath.move(to:CGPoint(x:0,y:0))bezierPath.addLine(to:CGPoint(x:100,y:100))bezierPath.addLine(to:CGPoint(x:200,y:50))bezierPath.addLine(to:CGPoint(

swift - 使用 UIBezierPath 点绘制矩形时如何圆角

我使用UIBezierPath逐点添加创建了一个矩形,现在我想圆角这个矩形的角,但似乎没有办法做到这一点。谁能帮帮我?classRectangleLayer:CAShapeLayer{letanimationDuration:CFTimeInterval=0.5overrideinit(){super.init()fillColor=Colors.clear.CGColorlineWidth=5.0path=rectanglePathStart.CGPath}requiredinit?(coderaDecoder:NSCoder){fatalError("init(coder:)has

ios - 使用 Swift 在圆形 UIView 中设置边框

我正在尝试制作一个带边框的UIView,但我只让它出现在UIView中,而不仅仅是在圆圈上。在棕色圆圈中我想要一个黑色边框,但它必须在圆圈中而不是在UIView中。我有一个名为Ball的类,我在其中绘制圆圈。classBall:UIView{vardesiredColour=UIColor.blueColor()structmine{staticvarp=UIBezierPath(ovalInRect:CGRectMake(0,0,118,117))}overridefuncdrawRect(rect:CGRect){//DrawingcodedesiredColour.setFill

ios - 使用 Playgrounds 在 Swift 中使用 UIBezierPath

我是否必须创建自定义类才能在SwiftPlayground中使用BezierPath?下面的代码只显示黑色背景:importUIKitimportXCPlaygroundclassGraphView:UIView{overridefuncdrawRect(rect:CGRect){letpath=UIBezierPath(rect:rect)path.moveToPoint(CGPointMake(0,0))path.addLineToPoint(CGPointMake(50,100))path.closePath()UIColor.redColor().setFill()path.s

ios - 如何更改 UIBezierPath 背景颜色?

我添加了这些代码行:varradius:CGFloat=UIScreen.mainScreen().bounds.width-60letpath:UIBezierPath=UIBezierPath(roundedRect:CGRect(x:0,y:0,width:UIScreen.mainScreen().bounds.width,height:UIScreen.mainScreen().bounds.height),cornerRadius:0)letcirclePath:UIBezierPath=UIBezierPath(roundedRect:CGRect(x:30,y:(UIS

ios - 带有 UIBezierPath 的 CAShapeLayer

我想像这样在UITableView单元格中显示三角形View。我设法使用打击代码完成了此任务。importUIKitclassTriangleView:UIView{overridefuncdrawRect(rect:CGRect){letwidth=self.layer.frame.widthletheight=self.layer.frame.heightletpath=CGPathCreateMutable()CGPathMoveToPoint(path,nil,0,0)CGPathAddLineToPoint(path,nil,width,0)CGPathAddLineToPo

ios - 设置线帽样式不起作用 UIBezierPath

这是我的代码:letcross=UIBezierPath()cross.move(to:CGPoint(x:skull.bounds.maxX,y:skull.bounds.minY))cross.addLine(to:CGPoint(x:skull.bounds.minX,y:skull.bounds.maxY))cross.close()UIColor.red.set()cross.lineWidth=3.0cross.lineCapStyle=.roundcross.stroke()我想把线的末端弄圆,但还是方的,怎么办? 最佳答案

swift - 如何将 UIView 裁剪成半圆?

我想将UIView裁剪成半圆形提前致谢。 最佳答案 一个方便的方法是继承UIView,在其上添加一个图层,如果默认情况下不是透明的,则使View颜色透明。importUIKitclassSemiCirleView:UIView{varsemiCirleLayer:CAShapeLayer!overridefunclayoutSubviews(){super.layoutSubviews()ifsemiCirleLayer==nil{letarcCenter=CGPoint(x:bounds.size.width/2,y:bounds

swift - 如何缩放 UIBezierPath 以适应当前 View (在 Swift 中)

我使用从PaintCode导入的代码创建了一个绘制咖啡杯的类,并将此类应用于View。使用@IBDesignable,我可以在Storyboard中看到杯子是在View内绘制的,但是整体形状太大了。我可以在代码中重新绘制形状以使其适合View的当前大小,但是在绘制形状后是否可以缩放形状以便当我的View在不同设备上更改大小时形状可以正确缩放?我调查了CGContextScaleCTM(aRef,,)但我不确定如何转换CGRect我的观点bounds到正确的比例因子本来不想全部贴出来的,但是我的绘图代码是这样开始的bezierPath.moveToPoint(CGPointMake(64

ios - 快速覆盖 UIView 中的默认图层类型

我想在swift中子类化UIView,并使用CAShapeLayer作为这个子类的图层类型——用layerClass()覆盖图层类型。如何访问CAShapeLayer中但不在CALayer中的属性-例如下面示例中的路径。下面的代码无法编译,因为path不是CALayer的成员。overrideclassfunclayerClass()->AnyClass{returnCAShapeLayer.self}overridefuncawakeFromNib(){varpath:UIBezierPath=UIBezierPath.init(ovalInRect:CGRectMake(0,0,3