Skip to content

Instantly share code, notes, and snippets.

View Quaggie's full-sized avatar

Jonathan Bijos Quaggie

  • Route
  • Rio de Janeiro
View GitHub Profile
// No MotorcycleTableViewCell
class MotorcycleTableViewCell: UITableViewCell {
static var height: CGFloat {
return 80
}
static var identifier: String {
return String(describing: self)
}
private func setupViews() {
contentView.addSubview(imgView)
contentView.addSubview(titleLabel)
contentView.addSubview(subtitleLabel)
imgView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 16).isActive = true
imgView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16).isActive = true
imgView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -16).isActive = true
imgView.widthAnchor.constraint(equalTo: imgView.heightAnchor).isActive = true
private let imgView: UIImageView = {
let iv = UIImageView()
iv.translatesAutoresizingMaskIntoConstraints = false
iv.contentMode = .scaleAspectFit
iv.clipsToBounds = true
return iv
}()
private let titleLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
private let imgView: UIImageView = {
return UIImageView()
}()
private let titleLabel: UILabel = {
return UILabel()
}()
private let subtitleLabel: UILabel = {
return UILabel()
}()
// [...]
private let imgView = UIImageView()
private let titleLabel = UILabel()
private let subtitleLabel = UILabel()
// [...]
private func setupViews() {
contentView.addSubview(imgView)
contentView.addSubview(titleLabel)
contentView.addSubview(subtitleLabel)
class MotorcycleTableViewCell: UITableViewCell {
var motorcycle: Motorcycle?
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setupViews()
}
required init?(coder aDecoder: NSCoder) {
class ViewController: UIViewController {
private let motorcycles: [Motorcycle]
private lazy var tableview: UITableView = {
let tableview = UITableView()
tableview.translatesAutoresizingMaskIntoConstraints = false
tableview.dataSource = self
tableview.contentInset = UIEdgeInsets(top: 16, left: 0, bottom: 16, right: 0)
return tableview
struct Motorcycle {
let image: UIImage
let name: String
let type: MotorcycleType
}
enum MotorcycleType: String {
case sport = "Sport bike"
case bigTrail = "Big Trail"
case custom = "Custom"
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
// [...]
}
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Monta a window de acordo com o tamanho da tela
window = UIWindow(frame: UIScreen.main.bounds)
// Instancia o ViewController
let vc = ViewController()
// Bota como tela principal dentro de uma navigationController
window?.rootViewController = UINavigationController(rootViewController: vc)
// Faz a window ser exibida
window?.makeKeyAndVisible()
return true