Tho*_*mas 57 rounded-corners uiimageview swift swift-playground
如何在Swift iOS Playground上制作带圆角的UIImageView?
里面需要填充颜色.
Mun*_*ndi 164
let imageView = UIImageView(frame: CGRectMake(0, 0, 100, 100))
imageView.backgroundColor = UIColor.redColor()
imageView.layer.cornerRadius = 8.0
imageView.clipsToBounds = true
Run Code Online (Sandbox Code Playgroud)
结果:

Jav*_*ría 25
对于swift中的圆形圆形图像框架,它对我有用的是:
self.profileImageView.image = UIImage(named:"profileUser")
self.profileImageView.layer.cornerRadius = self.profileImageView.frame.size.width / 2
self.profileImageView.clipsToBounds = true
Run Code Online (Sandbox Code Playgroud)
并添加阴影:
self.profileImageView.layer.masksToBounds = NO;
self.profileImageView.layer.cornerRadius = 8;
self.profileImageView.shadowOffset = CGSizeMake(5.0, 5.0);
self.profileImageView.shadowRadius = 5;
self.profileImageView.shadowOpacity = 0.5;
Run Code Online (Sandbox Code Playgroud)
Ron*_*oh1 20
试试这个,它对我有用.
self.profileImageView.layer.cornerRadius = self.profileImageView.frame.size.width / 2
self.profileImageView.clipsToBounds = true
Run Code Online (Sandbox Code Playgroud)
Evd*_*afa 14
我厌倦了为每个UIView 编写set radius和mask.所以我为UIView做了以下扩展.应该适用于每个UIView子类,尽管我还没有测试过它.对于您使用的特定视图,可以缩小扩展名.
extension UIView {
func setRadius(radius: CGFloat? = nil) {
self.layer.cornerRadius = radius ?? self.frame.width / 2;
self.layer.masksToBounds = true;
}
}
Run Code Online (Sandbox Code Playgroud)
如果您没有传递任何特定值,它将默认为视图的半宽.
| 归档时间: |
|
| 查看次数: |
79590 次 |
| 最近记录: |