首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UILabel Swift-3中显示的额外行

UILabel Swift-3中显示的额外行
EN

Stack Overflow用户
提问于 2016-11-09 23:14:55
回答 1查看 293关注 0票数 1

我正在设置uilabel层cornerRadius,有时标签在标签的某些角落/边缘有额外的线条,有办法避免这种情况吗?

请在屏幕截图下面找到。

代码:

代码语言:javascript
复制
//Message view
        let messageLabel = UILabel()
        messageLabel.backgroundColor = #someColor
        messageLabel.textColor = #someColor
        messageLabel.font = UIFont.systemFont(ofSize: 14)
        messageLabel.lineBreakMode = NSLineBreakMode.byWordWrapping
        messageLabel.attributedText = attributedString
        messageLabel.numberOfLines = 0
        messageLabel.textAlignment = .center
        messageLabel.shadowColor = UIColor.clear
        messageLabel.layer.cornerRadius = 3.0

        let maskPath = UIBezierPath(roundedRect: messageLabel.bounds,
                                    byRoundingCorners: [.topLeft, .topRight, .bottomRight],
                                    cornerRadii: CGSize(width: 18.0, height: 0.0))
        let maskLayer = CAShapeLayer()
        maskLayer.path = maskPath.cgPath
        messageLabel.layer.mask = maskLayer
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-10 00:52:12

如果x/y/width/height具有小数frame值,则可能会出现此类问题。

如果这是您的情况,请尝试使用以下函数之一对所有值进行舍入:round()ceil()floor()

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40517596

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档