in eCommerce/Views/Product/ProductView.swift [17:41]
func setup(with product: Product, in frame: CGRect) {
self.frame = frame
product.getImage { image in
DispatchQueue.main.async {
self.productImageView.image = image
}
}
productImageView.layer.cornerRadius = 10
titleLabel.text = product.name
if product.discountedPrice != product.price {
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: "$\(product.price)")
attributeString.addAttribute(NSAttributedString.Key.strikethroughStyle, value: 1, range: NSMakeRange(0, attributeString.length))
priceLabel.attributedText = attributeString
} else {
priceLabel.text = "$\(product.price)"
priceLabel.textColor = .white
}
discountLabel.text = "$\(product.discountedPrice)"
discountLabel.isHidden = product.discountedPrice == product.price
setNeedsLayout()
layoutIfNeeded()
}