ios – 仅显示UIView的角落

ios – 仅显示UIView的角落,第1张

概述如何仅显示UIView的角落? let view = UIView() view.layer.borderColor = UIColor.white.cgColor view.layer.borderWidth = 2 let maskframe = UIView(frame: CGRect(x:0, y:0, wid 如何仅显示UIVIEw的角落?

let vIEw = UIVIEw()        vIEw.layer.bordercolor = UIcolor.white.cgcolor        vIEw.layer.borderWIDth = 2            let maskframe = UIVIEw(frame: CGRect(x:0,y:0,wIDth:vIEw.frame.wIDth,height:vIEw.frame.height))         vIEw.layer.mask = maskframe.layer.`

这只掩盖了右边缘,我也不明白它是如何工作的.

解决方法 试试这个类,在这里我使用CoreGraphics自定义视图绘图,添加了一些Inspectable变量来帮助定制

////  CornerVIEw.swift//  CornersVIEwSO////  Created by ReinIEr Melian on 5/31/17.//  copyright © 2017 ReinIEr Melian. All rights reserved.//import UIKitimport CoreGraphics@IBDesignableclass CornerVIEw: UIVIEw {    @IBInspectable    var sizeMultiplIEr : CGfloat = 0.2{        dIDSet{            self.draw(self.bounds)        }    }    @IBInspectable    var linewidth : CGfloat = 2{        dIDSet{            self.draw(self.bounds)        }    }    @IBInspectable    var linecolor : UIcolor = UIcolor.black{        dIDSet{            self.draw(self.bounds)        }    }    overrIDe init(frame: CGRect) {        super.init(frame: frame)        self.backgroundcolor = UIcolor.clear    }    required init?(coder aDecoder: NSCoder) {        super.init(coder: aDecoder)        self.backgroundcolor = UIcolor.clear    }    func drawCorners()    {        let currentContext = UIGraphicsGetCurrentContext()        currentContext?.setlinewidth(linewidth)        currentContext?.setstrokecolor(linecolor.cgcolor)        //first part of top left corner        currentContext?.beginPath()        currentContext?.move(to: CGPoint(x: 0,y: 0))        currentContext?.addline(to: CGPoint(x: self.bounds.size.wIDth*sizeMultiplIEr,y: 0))        currentContext?.strokePath()        //top rigth corner        currentContext?.beginPath()        currentContext?.move(to: CGPoint(x: self.bounds.size.wIDth - self.bounds.size.wIDth*sizeMultiplIEr,y: 0))        currentContext?.addline(to: CGPoint(x: self.bounds.size.wIDth,y: self.bounds.size.height*sizeMultiplIEr))        currentContext?.strokePath()        //bottom rigth corner        currentContext?.beginPath()        currentContext?.move(to: CGPoint(x: self.bounds.size.wIDth,y: self.bounds.size.height - self.bounds.size.height*sizeMultiplIEr))        currentContext?.addline(to: CGPoint(x: self.bounds.size.wIDth,y: self.bounds.size.height))        currentContext?.addline(to: CGPoint(x: self.bounds.size.wIDth - self.bounds.size.wIDth*sizeMultiplIEr,y: self.bounds.size.height))        currentContext?.strokePath()        //bottom left corner        currentContext?.beginPath()        currentContext?.move(to: CGPoint(x: self.bounds.size.wIDth*sizeMultiplIEr,y: self.bounds.size.height))        currentContext?.addline(to: CGPoint(x: 0,y: self.bounds.size.height - self.bounds.size.height*sizeMultiplIEr))        currentContext?.strokePath()        //second part of top left corner        currentContext?.beginPath()        currentContext?.move(to: CGPoint(x: 0,y: self.bounds.size.height*sizeMultiplIEr))        currentContext?.addline(to: CGPoint(x: 0,y: 0))        currentContext?.strokePath()    }    // Only overrIDe draw() if you perform custom drawing.    // An empty implementation adversely affects performance during animation.    overrIDe func draw(_ rect: CGRect) {        // Drawing code        super.draw(rect)        self.drawCorners()    }}

EDITED

示例使用代码

import UIKitclass VIEwController: UIVIEwController {    var cornerVIEwCode : CornerVIEw?    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()        // Do any additional setup after loading the vIEw,typically from a nib.        self.cornerVIEwCode = CornerVIEw(frame: CGRect(x: 0,y: 0,wIDth: 50,height: 50))        self.vIEw.addSubvIEw(self.cornerVIEwCode!)    }    overrIDe func dIDReceiveMemoryWarning() {        super.dIDReceiveMemoryWarning()        // dispose of any resources that can be recreated.    }}

这就是它的样子

希望这可以帮助

总结

以上是内存溢出为你收集整理的ios – 仅显示UIView的角落全部内容,希望文章能够帮你解决ios – 仅显示UIView的角落所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1073298.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存