Repo created
This commit is contained in:
parent
4af19165ec
commit
68073add76
12458 changed files with 12350765 additions and 2 deletions
46
iphone/Maps/Core/Theme/Extensions/UIColor+hexString.swift
Normal file
46
iphone/Maps/Core/Theme/Extensions/UIColor+hexString.swift
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
extension UIColor {
|
||||
private func convertToHEX(component: CGFloat) -> Int {
|
||||
return lroundf(Float(component * 255));
|
||||
}
|
||||
|
||||
private var hexColorComponentTemplate: String {
|
||||
get {
|
||||
return "%02lX";
|
||||
}
|
||||
}
|
||||
|
||||
private var hexColorTemplate: String {
|
||||
get {
|
||||
return "#\(hexColorComponentTemplate)\(hexColorComponentTemplate)\(hexColorComponentTemplate)";
|
||||
}
|
||||
}
|
||||
|
||||
var hexString: String {
|
||||
get {
|
||||
let cgColorInRGB = cgColor.converted(to: CGColorSpace(name: CGColorSpace.sRGB)!, intent: .defaultIntent, options: nil)!
|
||||
let colorRef = cgColorInRGB.components
|
||||
let r = colorRef?[0] ?? 0
|
||||
let g = colorRef?[1] ?? 0
|
||||
let b = ((colorRef?.count ?? 0) > 2 ? colorRef?[2] : g) ?? 0
|
||||
let alpha = cgColor.alpha
|
||||
|
||||
var color = String(
|
||||
format: hexColorTemplate,
|
||||
convertToHEX(component: r),
|
||||
convertToHEX(component: g),
|
||||
convertToHEX(component: b)
|
||||
)
|
||||
|
||||
if (alpha < 1) {
|
||||
color += String(format: hexColorComponentTemplate, convertToHEX(component: alpha))
|
||||
}
|
||||
|
||||
return color
|
||||
}
|
||||
}
|
||||
|
||||
var sRGBColor: UIColor {
|
||||
let cgColorInRGB = cgColor.converted(to: CGColorSpace(name: CGColorSpace.sRGB)!, intent: .defaultIntent, options: nil)!
|
||||
return UIColor(cgColor: cgColorInRGB)
|
||||
}
|
||||
}
|
||||
11
iphone/Maps/Core/Theme/Extensions/UIColor+image.swift
Normal file
11
iphone/Maps/Core/Theme/Extensions/UIColor+image.swift
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
extension UIColor {
|
||||
func getImage() -> UIImage? {
|
||||
let rect = CGRect(x: 0, y: 0, width: 1, height: 1)
|
||||
UIGraphicsBeginImageContext(rect.size)
|
||||
self.setFill()
|
||||
UIRectFill(rect)
|
||||
let image = UIGraphicsGetImageFromCurrentImageContext()
|
||||
UIGraphicsEndImageContext()
|
||||
return image
|
||||
}
|
||||
}
|
||||
5
iphone/Maps/Core/Theme/Extensions/UIColor+rgba.swift
Normal file
5
iphone/Maps/Core/Theme/Extensions/UIColor+rgba.swift
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
extension UIColor {
|
||||
convenience init(_ r: CGFloat, _ g: CGFloat, _ b :CGFloat, _ a: CGFloat) {
|
||||
self.init(red: CGFloat(r/255.0), green: CGFloat(g/255.0), blue: CGFloat(b/255.0), alpha: a)
|
||||
}
|
||||
}
|
||||
18
iphone/Maps/Core/Theme/Extensions/UIFont+monospaced.swift
Normal file
18
iphone/Maps/Core/Theme/Extensions/UIFont+monospaced.swift
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import UIKit
|
||||
|
||||
extension UIFont {
|
||||
|
||||
/// Creates a UIFont object with monospaced numbers keeping other font descriptors like size and weight
|
||||
@objc var monospaced: UIFont {
|
||||
let attributes: [UIFontDescriptor.AttributeName: Any] = [
|
||||
.featureSettings: [
|
||||
[
|
||||
UIFontDescriptor.FeatureKey.type: kNumberSpacingType,
|
||||
UIFontDescriptor.FeatureKey.selector: kMonospacedNumbersSelector
|
||||
]
|
||||
]
|
||||
]
|
||||
let monospacedNumbersFontDescriptor = fontDescriptor.addingAttributes(attributes)
|
||||
return UIFont(descriptor: monospacedNumbersFontDescriptor, size: pointSize)
|
||||
}
|
||||
}
|
||||
23
iphone/Maps/Core/Theme/Extensions/UILabel+SetFontStyle.swift
Normal file
23
iphone/Maps/Core/Theme/Extensions/UILabel+SetFontStyle.swift
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
extension UILabel {
|
||||
func setFontStyle(_ font: FontStyleSheet, color: TextColorStyleSheet? = nil) {
|
||||
var name = font.rawValue
|
||||
if let color {
|
||||
name += ":\(color.rawValue)"
|
||||
}
|
||||
styleName = name
|
||||
}
|
||||
|
||||
func setFontStyle(_ color: TextColorStyleSheet) {
|
||||
styleName = color.rawValue
|
||||
}
|
||||
|
||||
func setFontStyleAndApply(_ font: FontStyleSheet, color: TextColorStyleSheet? = nil) {
|
||||
setFontStyle(font, color: color)
|
||||
applyTheme()
|
||||
}
|
||||
|
||||
func setFontStyleAndApply(_ color: TextColorStyleSheet) {
|
||||
setFontStyle(color)
|
||||
applyTheme()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
fileprivate struct AssociatedKeys {
|
||||
static var styleName: UInt8 = 0
|
||||
static var isStyleApplied: UInt8 = 1
|
||||
}
|
||||
|
||||
@objc extension UINavigationItem: StyleApplicable {
|
||||
@objc var styleName: String {
|
||||
get {
|
||||
isStyleApplied = false
|
||||
guard let value = objc_getAssociatedObject(self, &AssociatedKeys.styleName) as? String else {
|
||||
return ""
|
||||
}
|
||||
return value
|
||||
}
|
||||
set(newValue) {
|
||||
objc_setAssociatedObject(self, &AssociatedKeys.styleName, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
||||
}
|
||||
}
|
||||
|
||||
@objc var isStyleApplied: Bool {
|
||||
get {
|
||||
guard let value = objc_getAssociatedObject(self, &AssociatedKeys.isStyleApplied) as? Bool else {
|
||||
return false
|
||||
}
|
||||
return value
|
||||
}
|
||||
set(newValue) {
|
||||
objc_setAssociatedObject(self, &AssociatedKeys.isStyleApplied, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
||||
}
|
||||
}
|
||||
}
|
||||
46
iphone/Maps/Core/Theme/Extensions/UIView+SetStyle.swift
Normal file
46
iphone/Maps/Core/Theme/Extensions/UIView+SetStyle.swift
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
fileprivate struct AssociatedKeys {
|
||||
static var styleName: UInt8 = 0
|
||||
static var isStyleApplied: UInt8 = 1
|
||||
}
|
||||
|
||||
@objc extension UIView: StyleApplicable {
|
||||
@objc func sw_didMoveToWindow() {
|
||||
guard MapsAppDelegate.theApp().window === window else {
|
||||
sw_didMoveToWindow();
|
||||
return
|
||||
}
|
||||
applyTheme()
|
||||
isStyleApplied = true
|
||||
sw_didMoveToWindow();
|
||||
}
|
||||
|
||||
@objc var styleName: String {
|
||||
get {
|
||||
isStyleApplied = false
|
||||
guard let value = objc_getAssociatedObject(self, &AssociatedKeys.styleName) as? String else {
|
||||
return ""
|
||||
}
|
||||
return value
|
||||
}
|
||||
set(newValue) {
|
||||
objc_setAssociatedObject(self, &AssociatedKeys.styleName, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
||||
}
|
||||
}
|
||||
|
||||
@objc var isStyleApplied: Bool {
|
||||
get {
|
||||
guard let value = objc_getAssociatedObject(self, &AssociatedKeys.isStyleApplied) as? Bool else {
|
||||
return false
|
||||
}
|
||||
return value
|
||||
}
|
||||
set(newValue) {
|
||||
objc_setAssociatedObject(self, &AssociatedKeys.isStyleApplied, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
||||
}
|
||||
}
|
||||
|
||||
@objc func setStyleNameAndApply(_ styleName: String) {
|
||||
self.styleName = styleName
|
||||
applyTheme()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue