Caps-iOS/CapCollector/Presentation/CapCell.swift
Christoph Hagen 2806733b71 Version 1
2019-03-15 13:19:19 +01:00

47 lines
1022 B
Swift

//
// CapCell.swift
// CapFinder
//
// Created by User on 22.04.18.
// Copyright © 2018 User. All rights reserved.
//
import UIKit
class CapCell: UITableViewCell {
@IBOutlet private weak var capImage: RoundedImageView!
@IBOutlet private weak var matchLabel: UILabel!
@IBOutlet private weak var nameLabel: UILabel!
@IBOutlet weak var countLabel: UILabel!
var id = 0
var cap: Cap! {
didSet {
updateCell()
}
}
func updateCell() {
capImage.image = cap.image
//capImage.borderColor = AppDelegate.tintColor
matchLabel.text = text(for: cap.match)
nameLabel.text = cap.name
countLabel.text = "\(cap.id) (\(cap.count) image" + (cap.count > 1 ? "s)" : ")")
}
private func text(for value: Float?) -> String? {
guard let nr = value else {
return nil
}
let percent = Int((nr * 100).rounded())
return String(format: "%d %%", arguments: [percent])
}
}