有人有想法吗?
这是我的UIImageVIEw代码:
//Setup ProfileImageVIEw profileImageVIEw.layer.cornerRadius = profileImageVIEw.frame.size.wIDth / 2 profileImageVIEw.clipsToBounds = true profileImageVIEw.layer.bordercolor = UIcolor.white.cgcolor profileImageVIEw.layer.borderWIDth = 4.0 profileImageVIEw.layer.shadowOpacity = 0.12 profileImageVIEw.layer.shadowOffset = CGSize(wIDth: 0,height: 2) profileImageVIEw.layer.shadowRadius = 2 profileImageVIEw.layer.shadowcolor = UIcolor.black.cgcolor
和我的故事板设置:
我使用Xcode 10 beta 6 ……这可能是个问题吗?
解决方法 当您设置cornerRadius时,看起来图像正在从图层的边框中流失.看这篇文章: iOS: Rounded rectangle with border bleeds color@FelixLam在上述帖子中提出的CAShapeLayer解决方案可能是这样的:
let linewidth: CGfloat = 4.0 // the wIDth of the white border that you want to setlet imageWIDth = self.profileImageVIEw.bounds.wIDthlet imageHeight = self.profileImageVIEw.bounds.height// make sure wIDth and height are same before drawing a circleif (imageWIDth == imageHeight) { let sIDe = imageWIDth - linewidth let circularPath = UIBezIErPath.init(ovalIn: CGRect(linewidth / 2,linewidth / 2,sIDe,sIDe)) // add a new layer for the white border let borderLayer = CAShapeLayer() borderLayer.path = circularPath.CGPath borderLayer.linewidth = linewidth borderLayer.strokecolor = UIcolor.white.cgcolor borderLayer.fillcolor = UIcolor.clear.cgcolor self.profileImageVIEw.layer.insertSublayer(borderLayer,at: 0) // set the circle mask to your profile image vIEw let circularMask = CAShapeLayer() circularMask.path = circularPath.CGPath self.profileImageVIEw.layer.mask = circularMask}总结
以上是内存溢出为你收集整理的ios – Swift:在为UIImageView添加边框时获取小条带全部内容,希望文章能够帮你解决ios – Swift:在为UIImageView添加边框时获取小条带所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)