Skip to content

Instantly share code, notes, and snippets.

@rsaenzi
Last active March 12, 2020 04:14
Show Gist options
  • Save rsaenzi/e2ab2c4e78ee7ba12c9b534ec4982530 to your computer and use it in GitHub Desktop.
Save rsaenzi/e2ab2c4e78ee7ba12c9b534ec4982530 to your computer and use it in GitHub Desktop.
Template for custom table cell loaded from a .xib file
//
// CustomCell.swift
//
// Created by Rigoberto Sáenz Imbacuán (https://www.linkedin.com/in/rsaenzi/)
// Copyright © 2019. All rights reserved.
//
// Notes:
// - Bind content to the ContentView in Interface Builder
// - Make the xib's file owner be this class
import UIKit
class TableCell: UITableViewCell {
// This property must be bound to the ContentView view in Xcode Interface Builder
@IBOutlet private weak var content: UIView!
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
sharedInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
sharedInit()
}
private func sharedInit() {
loadNib()
addSubview(content)
// Expand to fill its parent
content.frame = self.bounds
content.autoresizingMask = [.flexibleHeight, .flexibleWidth]
}
}
@rsaenzi
Copy link
Author

rsaenzi commented Mar 12, 2020

@rsaenzi
Copy link
Author

rsaenzi commented Mar 12, 2020

@rsaenzi
Copy link
Author

rsaenzi commented Mar 12, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment