Commit 08a4f9e1 by Demid Merzlyakov

IOS-155: strikethrough on the purchase buttons.

parent e5ea3459
...@@ -30,8 +30,18 @@ class SubscriptionPurchaseButton: UIButton { ...@@ -30,8 +30,18 @@ class SubscriptionPurchaseButton: UIButton {
super.init(frame: .zero) super.init(frame: .zero)
self.translatesAutoresizingMaskIntoConstraints = false self.translatesAutoresizingMaskIntoConstraints = false
self.setAttributedTitle(buildTitle(), for: .normal) self.setAttributedTitle(buildTitle(), for: .normal)
self.backgroundColor = ThemeManager.currentTheme.subscriptionPurchaseBackgroundColor if type == .yearly {
self.setTitleColor(ThemeManager.currentTheme.subscriptionPurchaseColor, for: .normal) self.setTitleColor(ThemeManager.currentTheme.subscriptionPurchaseColor, for: .normal)
self.backgroundColor = ThemeManager.currentTheme.subscriptionPurchaseBackgroundColor
}
else {
self.setTitleColor(ThemeManager.currentTheme.subscriptionPurchaseBackgroundColor, for: .normal)
self.backgroundColor = ThemeManager.currentTheme.subscriptionPurchaseColor
}
self.layer.borderWidth = 1
self.layer.borderColor = ThemeManager.currentTheme.subscriptionPurchaseBackgroundColor.cgColor
self.clipsToBounds = true self.clipsToBounds = true
self.layer.cornerRadius = 6 self.layer.cornerRadius = 6
self.snp.makeConstraints { make in self.snp.makeConstraints { make in
...@@ -52,17 +62,39 @@ class SubscriptionPurchaseButton: UIButton { ...@@ -52,17 +62,39 @@ class SubscriptionPurchaseButton: UIButton {
let template = "subscription.button.\(showUpgradeText ? "upgrade" : "buy").\(subscriptionType.rawValue)".localized() let template = "subscription.button.\(showUpgradeText ? "upgrade" : "buy").\(subscriptionType.rawValue)".localized()
var withPrices = template.replacingOccurrences(of: "#PRICE#", with: price) let priceAttributes: [NSAttributedString.Key: Any]
if showUpgradeText {
priceAttributes = [
NSAttributedString.Key.font: AppFont.SFPro.light(size: 18),
NSAttributedString.Key.strikethroughStyle: NSUnderlineStyle.single.rawValue
]
}
else {
priceAttributes = [
NSAttributedString.Key.font: AppFont.SFPro.semibold(size: 18)
]
}
let priceValue = NSAttributedString(string: price, attributes: priceAttributes)
let resultAttributes = [
NSAttributedString.Key.font: AppFont.SFPro.semibold(size: 18)
]
let result = NSMutableAttributedString(string: template, attributes: resultAttributes)
result.replaceCharacters(in: (result.string as NSString).range(of: "#PRICE#"), with: priceValue)
if let discountSubscription = self.discountSubscription { if let discountSubscription = self.discountSubscription {
guard let discountPrice = discountSubscription.localizedPrice else { guard let discountPrice = discountSubscription.localizedPrice else {
return NSAttributedString() return NSAttributedString()
} }
withPrices = withPrices.replacingOccurrences(of: "#DISCOUNT_PRICE#", with: discountPrice)
let discountPriceRange = (result.string as NSString).range(of: "#DISCOUNT_PRICE#")
guard discountPriceRange.location != NSNotFound else {
return NSAttributedString()
}
result.replaceCharacters(in: discountPriceRange, with: discountPrice)
} }
var result = NSMutableAttributedString(string: withPrices)
#warning("Not implemented markup!")
//TODO: implement markup
return result return result
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment