swift3 有关View 只切上圆角 ,下面不切圆角 时,框线不见问题 ?

如图,上面两个圆角的框线不见了

图片描述

程式 如下,

 let companyTitleView = UIView(frame: CGRect(x: FrameWidth * 0.045, y: naviBar.frame.size.height + FrameWidth * 0.03, width: FrameWidth * 0.91, height: FrameWidth * 0.26))
    companyTitleView.backgroundColor = UIColor.white
    
    let radio:CGSize = CGSize(width: 10, height: 10)
    let corner:UIRectCorner = [.topLeft,.topRight]
    let path = UIBezierPath(roundedRect: companyTitleView.bounds, byRoundingCorners: corner, cornerRadii: radio)
    let masklayer:CAShapeLayer = CAShapeLayer()
    masklayer.frame = companyTitleView.bounds
    masklayer.path = path.cgPath
    companyTitleView.layer.mask = masklayer
    companyTitleView.layer.borderColor = myFunc.MYFUNC.colorHex("#CCCCCC").cgColor
    companyTitleView.layer.borderWidth = 1
    self.view.addSubview(companyTitleView)

请问各位大大,怎么让圆角的框线出现?感谢

阅读 3.7k
1 个回答

因为你的边框是原本View上的而且外边框不是圆角矩形,所有用mask裁剪之后自然就不见了。

你需要做的是,

  1. 原View自己的边框设置成圆角(但现在能这样做的话你还设啥圆角遮罩呢……),所以或者

  2. 原View不要边框,给有圆角遮罩加边框。也就是

let path = UIBezierPath()

这个对象。应该有stroke(边框线)相关的属性或方法。

参考:UIBezierPath

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进