美文网首页
自定义Cell

自定义Cell

作者: iwasee | 来源:发表于2017-07-31 15:25 被阅读12次

UICollectionViewCell

class ImageCollectionCell: UICollectionViewCell {

    var iv: UIImageView!

    override init(frame:CGRect)  {

        super.init(frame: frame)

        setupSubview()

    }

    required init?(coder aDecoder:NSCoder) {

        fatalError("init(coder:) has not been implemented")

    }

    func setupSubview() {

        let imageView = UIImageView()

        contentView.addSubview(imageView)

        imageView.contentMode = .scaleAspectFit

        iv = imageView

    }

    func setContentImage(_im:UIImage?) {

        iv.image = im

        setNeedsLayout()

    }

    override fun clayoutSubviews() {

        let width = UIScreen.main.bounds.width/2

        iv.frame = CGRect(x:0, y:0, width: width, height: width)

    }

}

UITableViewCell

相关文章

网友评论

      本文标题:自定义Cell

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