美文网首页
自定义 tableViewCll

自定义 tableViewCll

作者: 三更夜半鬼仇天 | 来源:发表于2018-09-24 12:31 被阅读0次
    //控件
        var icon = UIImageView()
        var title = UILabel()
    
     override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
            super.init(style: style, reuseIdentifier: reuseIdentifier)
    //控件实现
            self.addSubview(icon)
            self.addSubview(title)
            
        }
    
    //位置设置
     override func layoutSubviews() {
            super.layoutSubviews()
            //图片框
            let width = self.frame.width
            let height = self.frame.height
            let margin:CGFloat = 10.0//间距
            let iconX = margin
            let iconY = margin
            let iconH = height - 2 * margin
            let iconW = iconH * 1.2
            icon.frame = CGRect(x: iconX, y: iconY, width: iconW, height: iconH)
            icon.backgroundColor = UIColor.yellow
            //文本框
            let titleX = margin * 2 + iconW
            let titleY = margin
            let titleH = iconH
            let titleW = width - titleX - margin
            title.frame = CGRect(x: titleX, y: titleY, width: titleW, height: titleH)
            title.backgroundColor = .red
            
            
            
        }
        
        
        required init?(coder aDecoder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
        }
        
    

    相关文章

      网友评论

          本文标题:自定义 tableViewCll

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