Created
March 29, 2018 09:15
-
-
Save choiks14/d6e3cff6e92f85ea03b6619aea0d2b58 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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