Manos Chorianopoulos

fix TelcoViewController ui

......@@ -9,6 +9,7 @@ import UIKit
@objc public class TelcoViewController: UIViewController, UIPopoverControllerDelegate {
@IBOutlet weak var mainView: UIView!
@IBOutlet weak var backgroundImage: UIImageView!
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var scrollContentView: UIView!
@IBOutlet weak var heroImage: UIImageView!
......@@ -16,6 +17,15 @@ import UIKit
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var descriptionLabel: UILabel!
@IBOutlet weak var activateButton: UIButton!
@IBOutlet weak var valueView: UIView!
@IBOutlet weak var valueLabel: UILabel!
@IBOutlet weak var giftTypeLabel: UILabel!
@IBOutlet weak var giftDurationView: UIView!
@IBOutlet weak var giftDurationLabel: UILabel!
@IBOutlet weak var borderLineView: UIView!
@IBOutlet weak var moreButton: UIButton!
@IBOutlet weak var moreTextView: UITextView!
@IBOutlet weak var moreTextViewHeight: NSLayoutConstraint!
let uiscreen: CGRect = UIScreen.main.bounds
......@@ -24,6 +34,8 @@ import UIKit
var selectedNumber: String = ""
public var numbersList: Array<String> = []
var moreVisible: Bool = false;
public override func viewDidLoad() {
super.viewDidLoad()
......@@ -33,27 +45,76 @@ import UIKit
// Do any additional setup after loading the view.
getProfileRequest()
setBackButton()
setNavigationTitle("Ενεργοποίηση")
setBackButton("ic_close")
setNavigationTitle(ccms?._titleOffer ?? "")
backgroundImage.image = UIImage(named: "coupons_scrollview_white", in: Bundle(for: MyEmptyClass.self), compatibleWith: nil)
scrollView.clipsToBounds = true
scrollView.layer.cornerRadius = 30
scrollView.layer.maskedCorners = [ .layerMinXMinYCorner] // Top left corner radius
heroImage.load(link: ccms?._imageUrl ?? "", placeholder: UIImage(), cache: URLCache())
heroImage.load(link: ccms?._imageOfferUrl ?? "", placeholder: UIImage(), cache: URLCache())
heroImage.contentMode = .scaleAspectFill
heroImageHeight.constant = self.uiscreen.height * 0.25
nameLabel.text = ccms?._title ?? ""
descriptionLabel.text = ccms?._subtitle ?? ""
nameLabel.text = ccms?._description ?? ""
// descriptionLabel.text = ccms?._subtitle ?? ""
valueView.gradientBorder(width: 1, colors: [UIColor(rgb: 0x07A2D1), UIColor(rgb: 0x73CA34)], startPoint: .unitCoordinate(.bottomLeft), endPoint: .unitCoordinate(.topRight), andRoundCornersWithRadius: 35)
valueLabel.text = ccms?._giftValue ?? ""
giftTypeLabel.text = ccms?._giftType ?? ""
giftDurationLabel.text = ccms?._duration ?? ""
giftDurationView.frame = CGRect(x: 0.0, y: 0.0, width: giftDurationLabel.intrinsicContentSize.width + 20, height: giftDurationView.frame.height)
giftDurationView.gradientBorder(width: 2, colors: [UIColor(rgb: 0x65DD6B), UIColor(rgb: 0x0D81B8)], startPoint: .unitCoordinate(.left), endPoint: .unitCoordinate(.right), andRoundCornersWithRadius: 35)
borderLineView.applyGradient(colours: [UIColor(rgb: 0x0AA3CD), UIColor(rgb: 0x6ECA43)], gradient: GradientOrientation.horizontal, cornerRadius: 0.0)
activateButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Medium", size: 16)
activateButton.setTitle("Ενεργοποίηση", for: .normal)
activateButton.setTitleColor(.white, for: .normal)
activateButton.backgroundColor = UIColor(red: 0.47, green: 0.75, blue: 0.08, alpha: 1.00)
activateButton.layer.cornerRadius = 12.0
moreButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Regular", size: 16)
// termsButton.imageView?.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5)
moreButton.setTitle("Δες Περισσότερα", for: .normal)
moreButton.setTitleColor(UIColor(red: 0.25, green: 0.33, blue: 0.39, alpha: 1.00), for: .normal)
moreButton.setImage(UIImage(named: "ic_down_dark.png"), for: .normal)
// TODO: UNCOMMENT
// moreButton.setImage(UIImage(named: "ic_down_dark.png", in: Bundle(for: MyEmptyClass.self), compatibleWith: nil), for: .normal)
moreButton.semanticContentAttribute = .forceRightToLeft
moreButton.tintColor = UIColor(red: 0.21, green: 0.32, blue: 0.41, alpha: 1.00)
moreButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 0);
moreButton.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 5);
// let htmlText = ccms?._description ?? ""
// moreTextView.attributedText = htmlText.htmlToAttributedString
moreTextView.text = ccms?._termsAndConditions ?? ""
moreTextView.font = UIFont(name: "PFSquareSansPro-Regular", size: 13)
moreTextView.textColor = UIColor(rgb: 0x415564)
// moreTextView.textAlignment = .center
moreTextView.isScrollEnabled = false
toggleMore()
}
// MARK: - Functions
func toggleMore() {
if (moreVisible) {
moreTextView.isHidden = false
let targetSize = CGSize(width: moreTextView.frame.width, height: CGFloat(MAXFLOAT))
moreTextViewHeight.constant = moreTextView.sizeThatFits(targetSize).height
moreButton.setImage(UIImage(named: "ic_up_dark.png", in: Bundle(for: MyEmptyClass.self), compatibleWith: nil), for: .normal)
} else {
moreTextView.isHidden = true
moreTextViewHeight.constant = CGFloat(0)
moreButton.setImage(UIImage(named: "ic_down_dark.png", in: Bundle(for: MyEmptyClass.self), compatibleWith: nil), for: .normal)
}
}
func showConfirmDialog() -> Void {
let alert = UIAlertController(title: "Ενεργοποίηση υπηρεσίας", message: "Θέλετε να γίνει ενεργοποίηση στο Κινητό μου;", preferredStyle: .alert)
......@@ -162,6 +223,11 @@ import UIKit
@IBAction func activateButtomAction(_ sender: Any) {
self.numbersPopupTapped(sender)
}
@IBAction func moreButtonAction(_ sender: Any) {
moreVisible = !moreVisible
toggleMore()
}
}
// MARK: NumbersPopup
......
......@@ -8,23 +8,33 @@
import UIKit
extension UIViewController {
func setBackButton() {
func setBackButton(_ icon:String = "ic_back") {
let uiscreen: CGRect = UIScreen.main.bounds
let backButton = UIButton(type: UIButton.ButtonType.custom) as UIButton
if (icon == "ic_close") {
backButton.frame = CGRect(x: 0, y: 0, width: uiscreen.height * 0.025, height: uiscreen.height * 0.025)
} else {
backButton.frame = CGRect(x: 0, y: 0, width: uiscreen.height * 0.025, height: uiscreen.height * 0.02)
}
backButton.imageView!.contentMode = .scaleAspectFit
//backButton.setBackgroundImage(UIImage(named:Assets.Navigation.backButton), for: UIControlState())
backButton.setImage(UIImage(named: "ic_back", in: Bundle(for: MyEmptyClass.self), compatibleWith: nil), for: .normal)
backButton.setImage(UIImage(named: icon, in: Bundle(for: MyEmptyClass.self), compatibleWith: nil), for: .normal)
// backButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: -20, bottom: 0, right: 0)
backButton.addTarget(self, action: #selector(moveToBack(_:)), for: .touchUpInside)
backButton.translatesAutoresizingMaskIntoConstraints = false
// Add width, height constraints
if (icon == "ic_close") {
let widthContraints = NSLayoutConstraint(item: backButton, attribute: NSLayoutConstraint.Attribute.width, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: uiscreen.height * 0.025)
let heightContraints = NSLayoutConstraint(item: backButton, attribute: NSLayoutConstraint.Attribute.height, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: uiscreen.height * 0.025)
NSLayoutConstraint.activate([heightContraints,widthContraints])
} else {
let widthContraints = NSLayoutConstraint(item: backButton, attribute: NSLayoutConstraint.Attribute.width, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: uiscreen.height * 0.025)
let heightContraints = NSLayoutConstraint(item: backButton, attribute: NSLayoutConstraint.Attribute.height, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: uiscreen.height * 0.02)
NSLayoutConstraint.activate([heightContraints,widthContraints])
}
let leftBarButtonItem: UIBarButtonItem = UIBarButtonItem(customView: backButton)
self.navigationItem.setLeftBarButton(leftBarButtonItem, animated: false)
......@@ -217,3 +227,65 @@ extension UIFont {
return self.systemFont(ofSize: pointSize, weight: .medium)
}
}
public extension UIView {
private static let kLayerNameGradientBorder = "GradientBorderLayer"
func gradientBorder(width: CGFloat,
colors: [UIColor],
startPoint: CGPoint = CGPoint(x: 0.5, y: 0.0),
endPoint: CGPoint = CGPoint(x: 0.5, y: 1.0),
andRoundCornersWithRadius cornerRadius: CGFloat = 0) {
let existingBorder = gradientBorderLayer()
let border = existingBorder ?? CAGradientLayer()
border.frame = CGRect(x: bounds.origin.x, y: bounds.origin.y,
width: bounds.size.width + width, height: bounds.size.height + width)
border.colors = colors.map { return $0.cgColor }
border.startPoint = startPoint
border.endPoint = endPoint
let mask = CAShapeLayer()
let maskRect = CGRect(x: bounds.origin.x + width/2, y: bounds.origin.y + width/2,
width: bounds.size.width - width, height: bounds.size.height - width)
mask.path = UIBezierPath(roundedRect: maskRect, cornerRadius: cornerRadius).cgPath
mask.fillColor = UIColor.clear.cgColor
mask.strokeColor = UIColor.white.cgColor
mask.lineWidth = width
border.mask = mask
let exists = (existingBorder != nil)
if !exists {
layer.addSublayer(border)
}
}
private func gradientBorderLayer() -> CAGradientLayer? {
let borderLayers = layer.sublayers?.filter { return $0.name == UIView.kLayerNameGradientBorder }
if borderLayers?.count ?? 0 > 1 {
fatalError()
}
return borderLayers?.first as? CAGradientLayer
}
}
public extension CGPoint {
enum CoordinateSide {
case topLeft, top, topRight, right, bottomRight, bottom, bottomLeft, left
}
static func unitCoordinate(_ side: CoordinateSide) -> CGPoint {
switch side {
case .topLeft: return CGPoint(x: 0.0, y: 0.0)
case .top: return CGPoint(x: 0.5, y: 0.0)
case .topRight: return CGPoint(x: 1.0, y: 0.0)
case .right: return CGPoint(x: 0.0, y: 0.5)
case .bottomRight: return CGPoint(x: 1.0, y: 1.0)
case .bottom: return CGPoint(x: 0.5, y: 1.0)
case .bottomLeft: return CGPoint(x: 0.0, y: 1.0)
case .left: return CGPoint(x: 1.0, y: 0.5)
}
}
}
......