HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – Swift:在为UIImageView添加边框时获取小条带大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
当我为UI ImageView添加边框时,我会在下面的图片上看到小黑条.我在真正的iPhone上试用我的应用程序,我也可以看到小条带.我怎样才能删除这个问题或者问题出在哪里?

有人有想法吗?

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

和我的故事板设置:

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

我使用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 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,请注明来意。
标签: