美文网首页
Swift开发---正确姿势设置xib控件中的layer层

Swift开发---正确姿势设置xib控件中的layer层

作者: 大一号 | 来源:发表于2016-10-22 00:14 被阅读79次

问题:

前两天在开发时使用xib创建了一个UITableviewCell, 而当我想使用代码设置cell上的UIImageView的圆角时, 却没有效果.

原因:

使用xib初始化视图时, 会执行awakeFromNib方法, 且这个方法只会执行一次.

解决办法:

 这时候我只需要把设置圆角的操作放在layoutSubviews方法中就可以了. 样例代码如下

override func layoutSubviews() {

self.imageView?.layer.cornerRadius = imageView?.frame.size.width /2

self.imageView?.layer.masksToBounds=true

}

相关文章

网友评论

      本文标题:Swift开发---正确姿势设置xib控件中的layer层

      本文链接:https://www.haomeiwen.com/subject/sricuttx.html