Skip to content

Instantly share code, notes, and snippets.

@choiks14
Created March 29, 2018 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save choiks14/d6e3cff6e92f85ea03b6619aea0d2b58 to your computer and use it in GitHub Desktop.
Save choiks14/d6e3cff6e92f85ea03b6619aea0d2b58 to your computer and use it in GitHub Desktop.
import Foundation
import UIKit
import SnapKit
/********************************************************************************
1.view 구조
-contentview
-titleLabel
2.extension 구조
(1).init
(2).bind
(99).snapkit
*********************************************************************************/
/********************************************************************************
1.init
*********************************************************************************/
class MainTableViewCell: UITableViewCell {
//setup flag
var didSetupConstraints = false
//title
var titleLabel: UILabel = {
let label = UILabel()
label.font = .systemFont(ofSize: 15)
return label
}()
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupUI()
}
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setupUI()
}
}
/********************************************************************************
2.bind
*********************************************************************************/
extension MainTableViewCell {
func bind(title: String) {
self.titleLabel.text = title
}
}
/********************************************************************************
99.snapkit
*********************************************************************************/
extension MainTableViewCell {
func setupUI() {
self.contentView.backgroundColor = .white
//titleLabel
self.contentView.addSubview(self.titleLabel)
self.setNeedsUpdateConstraints()
}
//updateConstraints
override func updateConstraints() {
if (!didSetupConstraints) {
//titlelabel
self.titleLabel.snp.makeConstraints { (make) in
make.top.equalTo(self.contentView.snp.top).offset(10)
make.left.equalTo(self.contentView.snp.left).offset(10)
make.right.equalTo(self.contentView.snp.right).offset(-10)
make.bottom.equalTo(self.contentView.snp.bottom).offset(-10)
}
didSetupConstraints = true
}
super.updateConstraints()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment