forked from webleydev/Stevia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStevia+Content.swift
104 lines (87 loc) · 2.46 KB
/
Stevia+Content.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
// Stevia+Content.swift
// LoginStevia
//
// Created by Sacha Durand Saint Omer on 01/10/15.
// Copyright © 2015 Sacha Durand Saint Omer. All rights reserved.
//
#if canImport(UIKit)
import UIKit
public extension UIButton {
/**
Sets the title of the button for normal State
Essentially a shortcut for `setTitle("MyText", forState: .Normal)`
- Returns: Itself for chaining purposes
*/
@discardableResult
func text(_ t: String) -> Self {
setTitle(t, for: .normal)
return self
}
/**
Sets the localized key for the button's title in normal State
Essentially a shortcut for `setTitle(NSLocalizedString("MyText", comment: "")
, forState: .Normal)`
- Returns: Itself for chaining purposes
*/
@discardableResult
func textKey(_ t: String) -> Self {
text(NSLocalizedString(t, comment: ""))
return self
}
/**
Sets the image of the button in normal State
Essentially a shortcut for `setImage(UIImage(named:"X"), forState: .Normal)`
- Returns: Itself for chaining purposes
*/
@discardableResult
func image(_ s: String) -> Self {
setImage(UIImage(named: s), for: .normal)
return self
}
}
public extension UITextField {
/**
Sets the textfield placeholder but in a chainable fashion
- Returns: Itself for chaining purposes
*/
@discardableResult
func placeholder(_ t: String) -> Self {
placeholder = t
return self
}
}
public extension UILabel {
/**
Sets the label text but in a chainable fashion
- Returns: Itself for chaining purposes
*/
@discardableResult
func text(_ t: String) -> Self {
text = t
return self
}
/**
Sets the label localization key but in a chainable fashion
Essentially a shortcut for `text = NSLocalizedString("X", comment: "")`
- Returns: Itself for chaining purposes
*/
@discardableResult
func textKey(_ t: String) -> Self {
text(NSLocalizedString(t, comment: ""))
return self
}
}
extension UIImageView {
/**
Sets the image of the imageView but in a chainable fashion
Essentially a shortcut for `image = UIImage(named: "X")`
- Returns: Itself for chaining purposes
*/
@discardableResult
public func image(_ t: String) -> Self {
image = UIImage(named: t)
return self
}
}
#endif