Commit e3abbe14 authored by Jose Blaya's avatar Jose Blaya
Browse files

Merge branch '220-piax-update-optionsviewcontroller' into...

Merge branch '220-piax-update-optionsviewcontroller' into '219-piax-show-error-banner-when-internet-is-unreachable'

Resolve "PIAX. Update OptionsViewController"

See merge request ios/vpn-ios!338
parents b78a1479 c4ecc623
This diff is collapsed.
//
// AutolayoutViewController+Styles.swift
// PIA VPN
//
// Created by Jose Antonio Blaya Garcia on 13/12/2018.
// Copyright © 2018 London Trust Media. All rights reserved.
//
import Foundation
import PIALibrary
extension AutolayoutViewController {
func styleNavigationBarWithTitle(_ title: String) {
let currentStatus = Client.providers.vpnProvider.vpnStatus
switch currentStatus {
case .connected:
let titleLabelView = UILabel(frame: CGRect.zero)
titleLabelView.style(style: TextStyle.textStyle6)
titleLabelView.text = title
Theme.current.applyCustomNavigationBar(navigationController!.navigationBar,
withTintColor: .white,
andBarTintColors: [UIColor.piaGreen,
UIColor.piaGreenDark20])
navigationItem.titleView = titleLabelView
setNeedsStatusBarAppearanceUpdate()
default:
let titleLabelView = UILabel(frame: CGRect.zero)
titleLabelView.style(style: Theme.current.palette.appearance == .dark ?
TextStyle.textStyle6 :
TextStyle.textStyle7)
titleLabelView.text = title
Theme.current.applyCustomNavigationBar(navigationController!.navigationBar,
withTintColor: nil,
andBarTintColors: nil)
navigationItem.titleView = titleLabelView
setNeedsStatusBarAppearanceUpdate()
}
}
}
//
// CAGradientLayer+Image.swift
// PIA VPN
//
// Created by Jose Antonio Blaya Garcia on 30/11/2018.
// Copyright © 2018 London Trust Media. All rights reserved.
//
import Foundation
extension CAGradientLayer {
convenience init(frame: CGRect, colors: [UIColor]) {
self.init()
self.frame = frame
self.colors = []
for color in colors {
self.colors?.append(color.cgColor)
}
startPoint = CGPoint(x: 0, y: 0)
endPoint = CGPoint(x: 0, y: 1)
}
func createGradientImage() -> UIImage? {
var image: UIImage? = nil
UIGraphicsBeginImageContext(bounds.size)
if let context = UIGraphicsGetCurrentContext() {
render(in: context)
image = UIGraphicsGetImageFromCurrentImageContext()
}
UIGraphicsEndImageContext()
return image
}
}
......@@ -13,58 +13,6 @@ import FXPageControl
extension Theme {
// MARK: Navigation bar
public func applyLightNavigationBar(_ navigationBar: UINavigationBar) {
navigationBar.tintColor = UIColor.piaGrey4
navigationBar.barTintColor = palette.lightBackground
}
/**
Set color values for a custom navigation bar.
- Parameter navigationBar: The navigationBar where the changes are going to be applied.
- Parameter tintColor: The tintColor for the navigationBar. If nil: self.palette.textColor(forRelevance: 1, appearance: .dark)
- Parameter barTintColors: Array of colors for the background of the navigationBar. If the array contains 2 colors, it will generate a gradient. If the array contains more than 2 colors or nil, it will set the default value: self.palette.lightBackground. If the array only contains 1 color, a solid background color will be set.
*/
public func applyCustomNavigationBar(_ navigationBar: UINavigationBar,
withTintColor tintColor: UIColor?,
andBarTintColors barTintColors: [UIColor]?) {
UIView.animate(withDuration: 0.3) {
if let tintColor = tintColor {
navigationBar.tintColor = tintColor
} else {
navigationBar.tintColor = UIColor.piaGrey4
}
if let barTintColors = barTintColors,
barTintColors.count > 0,
barTintColors.count <= 2 {
if barTintColors.count == 1 {
navigationBar.barTintColor = barTintColors.first
navigationBar.setBackgroundImage(nil, for: UIBarMetrics.default)
} else {
var updatedFrame = navigationBar.bounds
updatedFrame.size.height += navigationBar.frame.origin.y
let gradientLayer = CAGradientLayer(frame: updatedFrame, colors: barTintColors)
navigationBar.setBackgroundImage(gradientLayer.createGradientImage(), for: UIBarMetrics.default)
}
} else {
navigationBar.barTintColor = self.palette.lightBackground
navigationBar.setBackgroundImage(nil, for: UIBarMetrics.default)
}
navigationBar.layoutIfNeeded()
}
}
public func applyLightBrandLogoNavigationBar(_ navigationBar: UINavigationBar) {
navigationBar.tintColor = palette.textColor(forRelevance: 1, appearance: .dark)
navigationBar.barTintColor = palette.lightBackground
}
// MARK: Typography
func applyHighlightedText(_ button: UIButton) {
......@@ -162,12 +110,4 @@ extension Theme {
TextStyle.textStyle6 : TextStyle.textStyle7)
}
/// :nodoc:
public func applySettingsCellTitle(_ label: UILabel, appearance: Appearance) {
if palette.appearance == Appearance.light {
label.style(style: TextStyle.textStyle7)
} else {
label.style(style: TextStyle.textStyle6)
}
}
}
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