• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - UIImageView 的图层边框可见插图

[复制链接]
菜鸟教程小白 发表于 2022-12-12 14:18:16 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

刚刚这样做:

self.imageView.backgroundColor = color1;
self.imageView.layer.masksToBounds = YES;
self.imageView.layer.borderColor = color1;
self.imageView.layer.borderWidth = 3.0;

这是问题的截图:

Screenshot of a problem

我可以看到图片、边框和图片片段超出边框...

enter image description here enter image description here

我该如何解决?



Best Answer-推荐答案


我在使用图层上的边框属性时遇到了类似的问题,并设法通过在顶部添加 CAShapeLayer 来解决它。
我无法告诉您它在旧设备上的表现如何,因为尚未使用许多动画等对其进行测试,但我真的怀疑它会减慢它们的速度。

以下是 Swift 中的一些代码:

    imageView.backgroundColor = UIColor(red: 0.1137, green: 0.2745, blue: 0.4627, alpha: 1.0)
    imageView.layer.masksToBounds = true
    imageView.layer.cornerRadius = imageView.bounds.height / 2.0

    let stroke:CAShapeLayer = CAShapeLayer()
    let rect = imageView.bounds
    let strokePath = UIBezierPath(roundedRect: rect, cornerRadius: imageView.bounds.height / 2.0)

    stroke.path = strokePath.CGPath
    stroke.fillColor = nil
    stroke.lineWidth = 3.0
    stroke.strokeColor = UIColor(red: 0.1137, green: 0.2745, blue: 0.4627, alpha: 1.0).CGColor

    stroke.frame = imageView.bounds
    imageView.layer.insertSublayer(stroke, atIndex: 1)

希望它也适用于您的情况

关于ios - UIImageView 的图层边框可见插图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28434313/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap