Manos Chorianopoulos

redesign CouponViewController

Showing 20 changed files with 153 additions and 11 deletions
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>SwiftWarplyFramework.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
</dict>
</plist>
......@@ -9,13 +9,18 @@ import UIKit
class CouponViewController: UIViewController {
@IBOutlet weak var mainView: UIView!
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var scrollContentView: UIView!
@IBOutlet weak var couponImageHeight: NSLayoutConstraint!
@IBOutlet weak var redeemButton: UIButton!
@IBOutlet weak var termsLabel: UILabel!
@IBOutlet weak var termsButton: UIButton!
@IBOutlet weak var termsTextView: UITextView!
@IBOutlet weak var termsTextViewHeight: NSLayoutConstraint!
let uiscreen: CGRect = UIScreen.main.bounds
var termsVisible: Bool = false;
override func viewDidLoad() {
super.viewDidLoad()
......@@ -23,31 +28,55 @@ class CouponViewController: UIViewController {
setBackButton()
setNavigationTitle("Εκπτωτικό κουπόνι")
mainView.clipsToBounds = true
mainView.layer.cornerRadius = 30
mainView.layer.maskedCorners = [ .layerMinXMinYCorner] // Top left corner radius
scrollView.clipsToBounds = true
scrollView.layer.cornerRadius = 30
scrollView.layer.maskedCorners = [ .layerMinXMinYCorner] // Top left corner radius
couponImageHeight.constant = self.uiscreen.height * 0.25
redeemButton.titleLabel?.font = UIFont.systemFont(ofSize: 15, weight: .medium)
termsLabel.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.medium)
let tap = UITapGestureRecognizer(target: self, action: #selector(CouponViewController.termsTapFunction))
termsLabel.isUserInteractionEnabled = true
termsLabel.addGestureRecognizer(tap)
termsButton.titleLabel?.font = .systemFont(ofSize: 15.0, weight: .semibold)
// termsButton.imageView?.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5)
let htmlText = "<p>Το κουπόνι ισχύει έως 05/12/2022</p>\n"
termsTextView.attributedText = htmlText.htmlToAttributedString
termsTextView.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.regular)
termsTextView.textColor = UIColor(red: 0.25, green: 0.33, blue: 0.39, alpha: 1.00)
termsTextView.textAlignment = .center
termsTextView.isScrollEnabled = false
toggleTerms()
}
// MARK: - Functions
func toggleTerms() {
if (termsVisible) {
termsTextView.isHidden = false
let targetSize = CGSize(width: termsTextView.frame.width, height: CGFloat(MAXFLOAT))
termsTextViewHeight.constant = termsTextView.sizeThatFits(targetSize).height
// MARK: - Actions
termsButton.setImage(UIImage(named: "ic_up_dark.png"), for: .normal)
} else {
termsTextView.isHidden = true
termsTextViewHeight.constant = CGFloat(0)
@objc func termsTapFunction(sender:UITapGestureRecognizer) {
print("Terms tapped!")
termsButton.setImage(UIImage(named: "ic_down_dark.png"), for: .normal)
}
}
// MARK: - Actions
@IBAction func redeemButtomAction(_ sender: Any) {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
let vc = storyboard.instantiateViewController(withIdentifier: "MakeItAPresentViewController") as UIViewController
self.navigationController?.pushViewController(vc, animated: true)
}
@IBAction func termsButtonAction(_ sender: Any) {
termsVisible = !termsVisible
toggleTerms()
}
}
......
{
"images" : [
{
"filename" : "coupons_scrollview_white.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "coupons_scrollview_white-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "coupons_scrollview_white-2.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "ic_down_dark.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ic_down_dark-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "ic_down_dark-2.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "ic_up_dark.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ic_up_dark-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "ic_up_dark-2.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
......@@ -49,3 +49,17 @@ extension UIViewController {
}
}
extension String {
var htmlToAttributedString: NSAttributedString? {
guard let data = data(using: .utf8) else { return nil }
do {
return try NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding:String.Encoding.utf8.rawValue], documentAttributes: nil)
} catch {
return nil
}
}
var htmlToString: String {
return htmlToAttributedString?.string ?? ""
}
}
......
......@@ -75,6 +75,7 @@ public class swiftApi {
public let inner_text: String?
public let buyable: Bool?
public let visible: Bool?
public let terms: String?
public init(dictionary: [String: Any]) {
self.uuid = dictionary["uuid"] as? String? ?? ""
......@@ -88,6 +89,7 @@ public class swiftApi {
self.inner_text = dictionary["inner_text"] as? String? ?? ""
self.buyable = dictionary["buyable"] as? Bool? ?? false
self.visible = dictionary["visible"] as? Bool? ?? false
self.terms = dictionary["terms"] as? String? ?? ""
let expirationObject = dictionary["expiration"] as? [String: Any]? ?? ["":""]
let expirationString = expirationObject?["value"] as? String? ?? ""
......