Commit 1635be60 authored by Jose Blaya's avatar Jose Blaya
Browse files

Merge branch '52-import-new-colors-and-fonts' into 'release/2.0.0'

Resolve "Import new colors and fonts"

See merge request ios/client-library-apple!108
parents ab6aff5f ea9e2eb2
Pod::Spec.new do |s|
s.name = "PIALibrary"
s.version = "1.1.4"
s.version = "2.0.0"
s.summary = "PIA client library in Swift."
s.homepage = "https://www.privateinternetaccess.com/"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "Davide De Rosa" => "davide@londontrustmedia.com" }
s.author = { "Davide De Rosa" => "davide@londontrustmedia.com", "Jose Blaya" => "joseblaya@londontrustmedia.com" }
s.source = { :git => "https://github.com/pia-foss/client-library-apple.git", :tag => "v#{s.version}" }
s.ios.deployment_target = "9.0"
......
This diff is collapsed.
......@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>2.0.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
......
//
// PIAColors.swift
// PIALibrary-iOS
//
// Created by Jose Antonio Blaya Garcia on 3/9/18.
// Copyright © 2018 London Trust Media. All rights reserved.
//
import Foundation
import UIKit
extension UIColor {
class var grey15: UIColor {
return UIColor(red: 34.0 / 255.0, green: 37.0 / 255.0, blue: 46.0 / 255.0, alpha: 1.0)
}
class var grey18: UIColor {
return UIColor(red: 43.0 / 255.0, green: 46.0 / 255.0, blue: 57.0 / 255.0, alpha: 1.0)
}
class var grey20: UIColor {
return UIColor(red: 50.0 / 255.0, green: 54.0 / 255.0, blue: 66.0 / 255.0, alpha: 1.0)
}
class var grey40: UIColor {
return UIColor(red: 92.0 / 255.0, green: 99.0 / 255.0, blue: 112.0 / 255.0, alpha: 1.0)
}
class var grey55: UIColor {
return UIColor(red: 136.0 / 255.0, green: 144.0 / 255.0, blue: 153.0 / 255.0, alpha: 1.0)
}
class var grey85: UIColor {
return UIColor(red: 215.0 / 255.0, green: 216.0 / 255.0, blue: 217.0 / 255.0, alpha: 1.0)
}
class var white: UIColor {
return UIColor(white: 1.0, alpha: 1.0)
}
class var grey92: UIColor {
return UIColor(white: 238.0 / 255.0, alpha: 1.0)
}
class var green: UIColor {
return UIColor(red: 93.0 / 255.0, green: 223.0 / 255.0, blue: 90.0 / 255.0, alpha: 1.0)
}
class var greenDark20: UIColor {
return UIColor(red: 76.0 / 255.0, green: 182.0 / 255.0, blue: 73.0 / 255.0, alpha: 1.0)
}
class var greenDark50: UIColor {
return UIColor(red: 3.0 / 255.0, green: 121.0 / 255.0, blue: 0.0, alpha: 1.0)
}
class var yellow: UIColor {
return UIColor(red: 249.0 / 255.0, green: 207.0 / 255.0, blue: 1.0 / 255.0, alpha: 1.0)
}
class var yellowDark: UIColor {
return UIColor(red: 230.0 / 255.0, green: 180.0 / 255.0, blue: 0.0, alpha: 1.0)
}
class var red: UIColor {
return UIColor(red: 242.0 / 255.0, green: 68.0 / 255.0, blue: 88.0 / 255.0, alpha: 1.0)
}
class var redDark: UIColor {
return UIColor(red: 178.0 / 255.0, green: 53.0 / 255.0, blue: 45.0 / 255.0, alpha: 1.0)
}
}
//
// PIAFonts.swift
// PIALibrary
//
// Created by Jose Antonio Blaya Garcia on 3/9/18.
// Copyright © 2018 London Trust Media. All rights reserved.
//
import UIKit
private enum Fonts {
static let robotoTextRegular = "Roboto-Regular"
}
extension UIFont {
public class func regularFontWith(size: CGFloat) -> UIFont! {
return UIFont(name: Fonts.robotoTextRegular, size: size)
}
}
//
// StyleGuideHelpers.swift
// PIALibrary-iOS
//
// Created by Jose Antonio Blaya Garcia on 3/9/18.
// Copyright © 2018 London Trust Media. All rights reserved.
//
import UIKit
// MARK: Structs
public struct TextStyle {
public let font: UIFont?
public let color: UIColor?
public let foregroundColor: UIColor?
public let backgroundColor: UIColor?
public let tintColor: UIColor?
public let lineHeight: CGFloat?
public init(font: UIFont?,
color: UIColor?,
foregroundColor: UIColor?,
backgroundColor: UIColor?,
tintColor: UIColor?,
lineHeight: CGFloat? = 0) {
self.font = font
self.color = color
self.foregroundColor = foregroundColor
self.backgroundColor = backgroundColor
self.tintColor = tintColor
self.lineHeight = lineHeight
}
}
public struct ViewStyle {
let backgroundColor: UIColor?
let tintColor: UIColor?
let layerStyle: LayerStyle?
public init(backgroundColor: UIColor?, tintColor: UIColor?, layerStyle: LayerStyle?) {
self.backgroundColor = backgroundColor
self.tintColor = tintColor
self.layerStyle = layerStyle
}
public struct LayerStyle {
let masksToBounds: Bool?
let cornerRadius: CGFloat?
let borderStyle: BorderStyle?
let shadowStyle: ShadowStyle?
public init(masksToBounds: Bool?, cornerRadius: CGFloat?, borderStyle: BorderStyle?, shadowStyle: ShadowStyle?) {
self.masksToBounds = masksToBounds
self.cornerRadius = cornerRadius
self.borderStyle = borderStyle
self.shadowStyle = shadowStyle
}
public struct BorderStyle {
let color: UIColor
let width: CGFloat
public init(color: UIColor, width: CGFloat) {
self.width = width
self.color = color
}
}
public struct ShadowStyle {
let color: UIColor
let radius: CGFloat
let offset: CGSize
let opacity: Float
public init(color: UIColor, radius: CGFloat, offset: CGSize, opacity: Float) {
self.radius = radius
self.color = color
self.offset = offset
self.opacity = opacity
}
}
}
}
public struct TextAttributeStyle {
let kern: CGFloat?
let paragraphStyle: NSMutableParagraphStyle?
let foregroundColor: UIColor?
let font: UIFont?
let link: String?
let baselineOffset: CGFloat?
public init(kern: CGFloat?, paragraphStyle: NSMutableParagraphStyle?, foregroundColor: UIColor?,
font: UIFont?, link: String?, baselineOffset: CGFloat?) {
self.kern = kern
self.paragraphStyle = paragraphStyle
self.foregroundColor = foregroundColor
self.font = font
self.link = link
self.baselineOffset = baselineOffset
}
func toAttributeArray() -> [NSAttributedStringKey: Any] {
var array = [NSAttributedStringKey: Any]()
array[NSAttributedStringKey.kern] = kern
array[NSAttributedStringKey.paragraphStyle] = paragraphStyle
array[NSAttributedStringKey.foregroundColor] = foregroundColor
array[NSAttributedStringKey.font] = font
array[NSAttributedStringKey.link] = link
array[NSAttributedStringKey.baselineOffset] = baselineOffset
return array
}
}
// MARK: Helper extensions
extension UIView: ViewStyling {
public func style(style: ViewStyle) {
if let backgroundColor = style.backgroundColor {
self.backgroundColor = backgroundColor
}
if let tintColor = style.tintColor {
self.tintColor = tintColor
}
if let layerStyle = style.layerStyle {
if let cornerRadius = layerStyle.cornerRadius {
self.layer.cornerRadius = cornerRadius
}
if let masksToBounds = layerStyle.masksToBounds {
self.layer.masksToBounds = masksToBounds
}
if let borderStyle = layerStyle.borderStyle {
self.layer.borderColor = borderStyle.color.cgColor
self.layer.borderWidth = borderStyle.width
}
if let shadowStyle = layerStyle.shadowStyle {
self.layer.applySketchShadow(color: shadowStyle.color,
alpha: shadowStyle.opacity,
offSet: shadowStyle.offset,
radius: shadowStyle.radius)
}
}
}
}
extension CALayer {
func applySketchShadow(
color: UIColor = .black,
alpha: Float = 0.12,
offSet: CGSize = CGSize.zero,
blur: CGFloat = 6,
radius: CGFloat = 2.0,
spread: CGFloat = 0)
{
shadowColor = color.cgColor
shadowOpacity = alpha
shadowOffset = offSet
shadowRadius = blur / 2.0
if spread == 0 {
shadowPath = nil
} else {
let dx = -spread
let rect = bounds.insetBy(dx: dx, dy: dx)
shadowPath = UIBezierPath(rect: rect).cgPath
}
}
}
extension UILabel: TextStyling {
public func style(style: TextStyle) {
font = style.font
textColor = style.color
if let lineHeight = style.lineHeight {
setLineHeight(lineHeight)
}
}
}
extension UIButton: TextStyling {
public func style(style: TextStyle) {
titleLabel?.font = style.font
setTitleColor(style.color, for: .normal)
backgroundColor = style.backgroundColor
}
public func style(style: TextStyle, for controlState: UIControlState) {
titleLabel?.font = style.font
setTitleColor(style.color, for: controlState)
if let color = style.backgroundColor {
backgroundColor = nil
setBackgroundImage(UIImage.fromColor(color), for: controlState)
} else {
backgroundColor = style.backgroundColor
}
}
}
extension UITextField: TextStyling {
public func style(style: TextStyle) {
font = style.font
textColor = style.color
placeholderColor = style.foregroundColor
tintColor = style.tintColor
}
}
extension UITextView: TextStyling {
public func style(style: TextStyle) {
font = style.font
textColor = style.color
}
}
//
// TextStyles.swift
// PIALibrary-iOS
//
// Created by Jose Antonio Blaya Garcia on 3/9/18.
// Copyright © 2018 London Trust Media. All rights reserved.
//
import UIKit
/// MARK: Helper protocols
protocol TextStyling {
func style(style: TextStyle)
}
public extension TextStyle {
public static let textStyle1 = TextStyle(
font: UIFont.regularFontWith(size: 14),
color: UIColor.white,
foregroundColor: nil,
backgroundColor: nil,
tintColor: nil,
lineHeight: 18
)
public static let textStyle2 = TextStyle(
font: UIFont.regularFontWith(size: 14),
color: UIColor.grey55,
foregroundColor: nil,
backgroundColor: nil,
tintColor: nil,
lineHeight: 18
)
public static let textStyle3 = TextStyle(
font: UIFont.regularFontWith(size: 14),
color: UIColor.greenDark20,
foregroundColor: nil,
backgroundColor: nil,
tintColor: nil,
lineHeight: 18
)
public static let textStyle4 = TextStyle(
font: UIFont.regularFontWith(size: 14),
color: UIColor.red,
foregroundColor: nil,
backgroundColor: nil,
tintColor: nil,
lineHeight: 18
)
public static let textStyle5 = TextStyle(
font: UIFont.regularFontWith(size: 14),
color: UIColor.grey20,
foregroundColor: nil,
backgroundColor: nil,
tintColor: nil,
lineHeight: 18
)
public static let textStyle6 = TextStyle(
font: UIFont.regularFontWith(size: 12),
color: UIColor.white,
foregroundColor: nil,
backgroundColor: nil,
tintColor: nil,
lineHeight: 16
)
public static let textStyle7 = TextStyle(
font: UIFont.regularFontWith(size: 12),
color: UIColor.grey55,
foregroundColor: nil,
backgroundColor: nil,
tintColor: nil,
lineHeight: 16
)
public static let textStyle8 = TextStyle(
font: UIFont.regularFontWith(size: 12),
color: UIColor.greenDark20,
foregroundColor: nil,
backgroundColor: nil,
tintColor: nil,
lineHeight: 16
)
public static let textStyle9 = TextStyle(
font: UIFont.regularFontWith(size: 12),
color: UIColor.red,
foregroundColor: nil,
backgroundColor: nil,
tintColor: nil,
lineHeight: 16
)
public static let textStyle10 = TextStyle(
font: UIFont.regularFontWith(size: 12),
color: UIColor.grey20,
foregroundColor: nil,
backgroundColor: nil,
tintColor: nil,
lineHeight: 16
)
public static let textStyle11 = TextStyle(
font: UIFont.regularFontWith(size: 10),
color: UIColor.white,
foregroundColor: nil,
backgroundColor: nil,
tintColor: nil,
lineHeight: 15
)
public static let textStyle12 = TextStyle(
font: UIFont.regularFontWith(size: 10),
color: UIColor.grey55,
foregroundColor: nil,
backgroundColor: nil,
tintColor: nil,
lineHeight: 15
)
public static let textStyle13 = TextStyle(
font: UIFont.regularFontWith(size: 10),
color: UIColor.greenDark20,
foregroundColor: nil,
backgroundColor: nil,
tintColor: nil,
lineHeight: 15
)
public static let textStyle14 = TextStyle(
font: UIFont.regularFontWith(size: 10),
color: UIColor.red,
foregroundColor: nil,
backgroundColor: nil,
tintColor: nil,
lineHeight: 15
)
public static let textStyle15 = TextStyle(
font: UIFont.regularFontWith(size: 10),
color: UIColor.grey20,
foregroundColor: nil,
backgroundColor: nil,
tintColor: nil,
lineHeight: 15
)
}
//
// ViewStyles.swift
// PIALibrary-iOS
//
// Created by Jose Antonio Blaya Garcia on 3/9/18.
// Copyright © 2018 London Trust Media. All rights reserved.
//
import UIKit
protocol ViewStyling {
func style(style: ViewStyle)
}
extension ViewStyle {
}
//
// UIImage+Color.swift
// PIALibrary-iOS
//
// Created by Jose Antonio Blaya Garcia on 3/9/18.
// Copyright © 2018 London Trust Media. All rights reserved.
//
import UIKit
/// Extension of the uiimage class, for simple helper methods.
public extension UIImage {
/// Method to create an image from a colour
/// - Parameter color: The colour to convert to image
/// - Returns: The image that is a colour
public static func fromColor(_ color: UIColor, height: CGFloat = 1.0) -> UIImage {
let rect = CGRect(x: 0, y: 0, width: 1, height: height)
UIGraphicsBeginImageContext(rect.size)
let context = UIGraphicsGetCurrentContext()
context?.setFillColor(color.cgColor)
context?.fill(rect)
let img = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return img ?? UIImage.fromColor(UIColor.clear)
}
}
//
// UILabel+LineHeight.swift
// PIALibrary-iOS
//
// Created by Jose Antonio Blaya Garcia on 3/9/18.
// Copyright © 2018 London Trust Media. All rights reserved.
//
import UIKit
public extension UILabel {
/// Add a specific height to the space between the label's lines.
///
/// - Parameter lineHeight: The space between lines to apply.
public func setLineHeight(_ lineHeight: CGFloat) {
let text = self.text
if let text = text {
let attributeString = NSMutableAttributedString(string: text)
let style = NSMutableParagraphStyle()
style.lineSpacing = lineHeight
attributeString.addAttribute(NSAttributedStringKey.paragraphStyle,
value: style,
range: NSRange(location: 0,
length: text.count))
self.attributedText = attributeString