ios – Swift:在为UIImageView添加边框时获取小条带

ios – Swift:在为UIImageView添加边框时获取小条带,第1张

概述当我为UI ImageView添加边框时,我会在下面的图片上看到小黑条.我在真正的iPhone上试用我的应用程序,我也可以看到小条带.我怎样才能删除这个问题或者问题出在哪里? 有人有想法吗? 这是我的UIImageView代码: //Setup ProfileImageView profileImageView.layer.cornerRadius = profileImageView.f 当我为UI ImageVIEw添加边框时,我会在下面的图片上看到小黑条.我在真正的iPhone上试用我的应用程序,我也可以看到小条带.我怎样才能删除这个问题或者问题出在哪里?

有人有想法吗?

这是我的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添加边框时获取小条带所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存