UIView圆角 - 斯威夫特2.0? [英] UIView rounded Corner - Swift 2.0?

查看:138
本文介绍了UIView圆角 - 斯威夫特2.0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将一些项目更新为Swift 2.0。我有一个视图,左上角有一个圆角。一切都在Swift< 1.2,但现在,再也没有圆角了。

Ill try to update some projects to Swift 2.0. I´ve got a View, with a rounded corner top left. Everything works fine in Swift < 1.2, but now, there is no rounded corner anymore.

没有警告,没有错误,没有圆角。

No Warnings, no Errors, just no rounded corner.

这是它在Swift< 1.2。

This is how it works in Swift < 1.2.

    let maskPath = UIBezierPath(roundedRect: contentView.bounds,byRoundingCorners: .TopLeft, cornerRadii: CGSize(width: 10.0, height: 10.0))
    let maskLayer = CAShapeLayer(layer: maskPath)
    maskLayer.frame = contentView.bounds
    maskLayer.path = maskPath.CGPath
    contentView.layer.mask = maskLayer

任何人都知道这里有什么问题吗?我没有在文档中找到任何更改。

Anyone know whats wrong here? Ill dont find any changes in the documentation.

推荐答案

Swift 2.0-2.1中的这段代码没有任何问题。您确定此代码段之前或之后没有其他内容影响您的观点吗?

There's nothing wrong with this piece of code in Swift 2.0–2.1. Are you sure there isn't something else before or after this code snippet, that's affecting your view?

这是一个快速的Playground,包含您的代码:

Here's a quick Playground with your code:

这篇关于UIView圆角 - 斯威夫特2.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆