大佬教程收集整理的这篇文章主要介绍了ios – Swift:在为UIImageView添加边框时获取小条带,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
有人有想法吗?
这是我的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 ……这可能是个问题吗?
@FelixLam在上述帖子中提出的CAShapeLayer解决方案可能是这样的:
let lineWidth: CGFloat = 4.0 // the width of the white border that you want to set let imageWidth = self.profileImageView.bounds.width let imageHeight = self.profileImageView.bounds.height // make sure width and height are same before drawing a circle if (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添加边框时获取小条带所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。