Skip to content

Instantly share code, notes, and snippets.

@abbood
Last active November 25, 2018 00:58
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 abbood/fa225e9580d15511b63a510395d77fc0 to your computer and use it in GitHub Desktop.
Save abbood/fa225e9580d15511b63a510395d77fc0 to your computer and use it in GitHub Desktop.
import AFDateHelper
import Foundation
import UIKit
protocol OrderReceiptTableViewCellDelegate: class {
func orderHistoryCellDidTouchTrack(_ cell: OrderHistoryTableViewCell)
}
final class OrderReceipt_Header_TableViewCell: UITableViewCell, CellViewPropertiesProviderProtocol {
// MARK: - CellViewPropertiesProviderProtocol
public var defaultCellHeight: CGFloat {
return UITableViewAutomaticDimension
}
// MARK: - init
static let cellIdentifier = "TTOrderReceiptTableViewCellIdentifier"
private var storeLabel: TTRLabel
private var storeName: String!
private var reorderButton: TTRUIButton
private var driverLabelKey: TTRLabel
private var driverLabelValue: TTRLabel
private var driverName: String!
private var timeLabelKey: TTRLabel
private var timeLabelValue: TTRLabel
private var time: String!
private var addressNickNameLabelKey: TTRLabel
private var addressNickNameLabelValue: TTRLabel
private var addressNickName: String!
private var view: UIView
private var didSetupConstraints = false
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
self.storeLabel = TTRLabel()
self.storeName = ""
self.reorderButton = TTRUIButton()
self.driverLabelKey = TTRLabel()
self.driverLabelValue = TTRLabel()
self.driverName = ""
self.timeLabelKey = TTRLabel()
self.timeLabelValue = TTRLabel()
self.time = ""
self.addressNickNameLabelKey = TTRLabel()
self.addressNickNameLabelValue = TTRLabel()
self.addressNickName = ""
self.didSetupConstraints = false
self.view = UIView();
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.setupViews()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - setup
private func setupViews() {
self.contentView.autoPinEdgesToSuperviewEdges() // if i don't add this line, cell height defaults to 44
self.addReorderButton()
self.addstoreLabel()
self.addOrderDetails()
}
private func addReorderButton() {
reorderButton = TTRButton(type: .Active(TTRString.For.Reorder.value.uppercased(), .white), size: .Small).instance
reorderButton.backgroundColor = TTRColor.darkGreenPrimary.value
reorderButton.layer.cornerRadius = 3
contentView.addSubview(self.reorderButton)
}
private func addstoreLabel() {
self.storeLabel.font = .ttrTitle
contentView.addSubview(self.storeLabel)
}
private func addOrderDetails() {
// driver label
self.driverLabelKey.font = .ttrCaptions
self.driverLabelKey.attributedText = NSMutableAttributedString.withLine(1.3,
letterSpace: TTRFont.KernningSpace.standard(.h4).value,
titleText: TTRString.For.DriverName.value.uppercased(),
color: TTRColor.blackPrimary.value)
// driver name
self.driverLabelValue.font = .ttrBody
// time label
self.timeLabelKey.font = .ttrCaptions
self.timeLabelKey.attributedText = NSMutableAttributedString.withLine(1.3,
letterSpace: TTRFont.KernningSpace.standard(.h4).value,
titleText: TTRString.For.Time.value.uppercased(),
color: TTRColor.blackPrimary.value)
// time
self.timeLabelValue.font = .ttrBody
// addressNickName Label
self.addressNickNameLabelKey.font = .ttrCaptions
self.addressNickNameLabelKey.attributedText = NSMutableAttributedString.withLine(1.3,
letterSpace: TTRFont.KernningSpace.standard(.h4).value,
titleText: TTRString.For.Address.value.uppercased(),
color: TTRColor.blackPrimary.value)
// addressNickName
self.addressNickNameLabelValue.font = .ttrBody
contentView.addSubview(self.driverLabelKey)
contentView.addSubview(self.driverLabelValue)
contentView.addSubview(self.timeLabelKey)
contentView.addSubview(self.timeLabelValue)
contentView.addSubview(self.addressNickNameLabelKey)
contentView.addSubview(self.addressNickNameLabelValue)
}
// MARK: - Setters
public func setStoreName(_ value:String) {
self.setStringToLabel(self.storeLabel, value)
}
public func setTime(_ value:String) {
self.setStringToLabel(self.timeLabelValue, value)
}
public func setDriverName(_ value:String) {
self.setStringToLabel(self.driverLabelValue, value)
}
public func setAddressNickname(_ value:String) {
self.setStringToLabel(self.addressNickNameLabelValue, value)
}
// MARK: - updateConstraints
override func updateConstraints()
{
if !didSetupConstraints {
reorderButton.autoPinEdge(.trailing, to: .trailing, of: contentView, withOffset: -15)
reorderButton.autoPinEdge(.top, to: .top, of: contentView, withOffset: 14)
reorderButton.autoSetDimensions(to: TTRButton.Size.Small.value)
storeLabel.autoPinEdge(.leading, to: .leading, of: contentView, withOffset: 15)
storeLabel.autoPinEdge(.top, to: .top, of: contentView, withOffset: 14)
storeLabel.autoPinEdge(.trailing, to: .leading, of: reorderButton, withOffset: 15)
driverLabelKey.autoPinEdge(.leading, to: .leading, of: contentView, withOffset: 15)
driverLabelKey.autoPinEdge(.top, to: .top, of: contentView, withOffset: 76)
driverLabelValue.autoPinEdge(.leading, to: .leading, of: contentView, withOffset: 100)
driverLabelValue.autoPinEdge(.top, to: .top, of: contentView, withOffset: 72)
driverLabelValue.autoAlignAxis(.baseline, toSameAxisOf: driverLabelKey)
timeLabelKey.autoPinEdge(.leading, to: .leading, of: contentView, withOffset: 15)
timeLabelKey.autoPinEdge(.top, to: .bottom, of: driverLabelKey, withOffset: 10)
timeLabelValue.autoPinEdge(.leading, to: .leading, of: contentView, withOffset: 100)
timeLabelValue.autoPinEdge(.top, to: .bottom, of: driverLabelValue, withOffset: 6)
timeLabelValue.autoAlignAxis(.baseline, toSameAxisOf: timeLabelKey)
addressNickNameLabelKey.autoPinEdge(.leading, to: .leading, of: contentView, withOffset: 15)
addressNickNameLabelKey.autoPinEdge(.top, to: .bottom, of: timeLabelKey, withOffset: 10)
addressNickNameLabelKey.autoPinEdge(.bottom, to: .bottom, of: contentView, withOffset: -26)
addressNickNameLabelValue.autoPinEdge(.leading, to: .leading, of: contentView, withOffset: 100)
addressNickNameLabelValue.autoPinEdge(.top, to: .bottom, of: timeLabelValue, withOffset: 6)
addressNickNameLabelValue.autoAlignAxis(.baseline, toSameAxisOf: addressNickNameLabelKey)
didSetupConstraints = true
}
super.updateConstraints()
}
// MARK: - Util
private func setStringToLabel(_ label: TTRLabel,_ text:String) {
label.attributedText = NSMutableAttributedString.withLine(1.3,
letterSpace: TTRFont.KernningSpace.standard(.h5).value,
titleText: text,
color: TTRColor.blackPrimary.value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment