-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIDatePicker+Extensions.swift
46 lines (39 loc) · 1.32 KB
/
UIDatePicker+Extensions.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// UIDatePicker+Extensions.swift
// OYExtensions
//
// Created by osmanyildirim
//
import UIKit
extension UIDatePicker: OYInit {
public typealias ViewType = UIDatePicker
/// Initializer method with `x, y, width, height` values
public static func oy_init(_ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) -> UIDatePicker {
let datePicker = UIDatePicker(frame: .oy_init(x, y, width, height))
return datePicker
}
/// Get and Set text color of UIDatePicker
public var oy_textColor: UIColor? {
get { value(forKeyPath: "textColor") as? UIColor }
set(value) { setValue(value, forKeyPath: "textColor") }
}
/// Get and Set indicator color of UIDatePicker
public var oy_indicatorColor: UIColor? {
get {
guard !subviews.isEmpty else { return nil }
if subviews[0].subviews.count > 1 {
return subviews[0].subviews[1].backgroundColor
}
return nil
}
set(value) {
guard !subviews.isEmpty else { return }
if subviews[0].subviews.count > 1 {
subviews[0].subviews[1].backgroundColor = value
}
if subviews[0].subviews.count > 2 {
subviews[0].subviews[2].backgroundColor = value
}
}
}
}