diff --git a/Cupcake.podspec b/Cupcake.podspec index cbad37a..ec2d5f6 100644 --- a/Cupcake.podspec +++ b/Cupcake.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Cupcake" - s.version = "1.0.0" + s.version = "1.1.0" s.summary = "An easy way to create and layout UI components for iOS." s.description = <<-DESC diff --git a/Cupcake/Alert.swift b/Cupcake/Alert.swift index 02e962b..b8270d6 100644 --- a/Cupcake/Alert.swift +++ b/Cupcake/Alert.swift @@ -26,10 +26,12 @@ import UIKit */ public var Alert: AlertMaker { + cpk_swizzleMethodsIfNeed() return AlertMaker(style: .alert) } public var ActionSheet: AlertMaker { + cpk_swizzleMethodsIfNeed() return AlertMaker(style: .actionSheet) } diff --git a/Cupcake/Button.swift b/Cupcake/Button.swift index 9db8a1e..2fe5ed3 100644 --- a/Cupcake/Button.swift +++ b/Cupcake/Button.swift @@ -9,6 +9,7 @@ import UIKit public var Button: UIButton { + cpk_swizzleMethodsIfNeed() let button = UIButton() cpk_higherHuggingAndResistance(forView: button) return button diff --git a/Cupcake/ImageView.swift b/Cupcake/ImageView.swift index adccf19..0e17ea4 100644 --- a/Cupcake/ImageView.swift +++ b/Cupcake/ImageView.swift @@ -9,6 +9,7 @@ import UIKit public var ImageView: UIImageView { + cpk_swizzleMethodsIfNeed() let imageView = UIImageView() cpk_higherHuggingAndResistance(forView: imageView) return imageView diff --git a/Cupcake/Label.swift b/Cupcake/Label.swift index 6b06061..f954fd0 100644 --- a/Cupcake/Label.swift +++ b/Cupcake/Label.swift @@ -9,6 +9,7 @@ import UIKit public var Label: UILabel { + cpk_swizzleMethodsIfNeed() let label = UILabel() return label } diff --git a/Cupcake/Stack.swift b/Cupcake/Stack.swift index d2a5f22..2d1b6f5 100644 --- a/Cupcake/Stack.swift +++ b/Cupcake/Stack.swift @@ -68,6 +68,7 @@ public enum CPKStackAlignment : Int { */ public func HStack(_ items: Any...) -> CPKStackView { + cpk_swizzleMethodsIfNeed() let stack = CPKStackView() stack.axis = .horizontal stack.alignment = .center @@ -76,6 +77,7 @@ public func HStack(_ items: Any...) -> CPKStackView { } public func VStack(_ items: Any...) -> CPKStackView { + cpk_swizzleMethodsIfNeed() let stack = CPKStackView() stack.axis = .vertical stack.alignment = .left diff --git a/Cupcake/StaticTable.swift b/Cupcake/StaticTable.swift index 4be0861..cb23ed9 100644 --- a/Cupcake/StaticTable.swift +++ b/Cupcake/StaticTable.swift @@ -36,20 +36,24 @@ import UIKit */ public func PlainTable(_ sectionsOrRows: Any...) -> StaticTableView { + cpk_swizzleMethodsIfNeed() let tableView = StaticTableView(sectionsOrRows: sectionsOrRows, style: .plain) tableView.tableFooterView = UIView() return tableView } public func GroupTable(_ sectionsOrRows: Any...) -> StaticTableView { + cpk_swizzleMethodsIfNeed() return StaticTableView(sectionsOrRows: sectionsOrRows, style: .grouped) } public func Section(_ rowsOrStrings: Any...) -> StaticSection { + cpk_swizzleMethodsIfNeed() return StaticSection(rowsOrStrings: rowsOrStrings) } public var Row: StaticRow { + cpk_swizzleMethodsIfNeed() return StaticRow() } diff --git a/Cupcake/TextField.swift b/Cupcake/TextField.swift index 85b026c..776d0b8 100644 --- a/Cupcake/TextField.swift +++ b/Cupcake/TextField.swift @@ -9,6 +9,7 @@ import UIKit public var TextField: UITextField { + cpk_swizzleMethodsIfNeed() let textField = UITextField() textField.enablesReturnKeyAutomatically = true textField.returnKeyType = .done diff --git a/Cupcake/TextView.swift b/Cupcake/TextView.swift index 80e93f2..c1ba659 100644 --- a/Cupcake/TextView.swift +++ b/Cupcake/TextView.swift @@ -9,6 +9,7 @@ import UIKit public var TextView: UITextView { + cpk_swizzleMethodsIfNeed() return UITextView().font(17) } diff --git a/Cupcake/View.swift b/Cupcake/View.swift index 112fcb9..cdeebfe 100644 --- a/Cupcake/View.swift +++ b/Cupcake/View.swift @@ -9,6 +9,7 @@ import UIKit public var View: UIView { + cpk_swizzleMethodsIfNeed() let view = UIView() return view } diff --git a/Cupcake/__Private__Implementations__.swift b/Cupcake/__Private__Implementations__.swift index 598caa7..8940b79 100644 --- a/Cupcake/__Private__Implementations__.swift +++ b/Cupcake/__Private__Implementations__.swift @@ -601,28 +601,31 @@ extension NSMutableAttributedString { fileprivate var __flagForMethodSwizzle__: Bool = false +func cpk_swizzleMethodsIfNeed() { + if !__flagForMethodSwizzle__ { + __flagForMethodSwizzle__ = true + + UIView.cpk_swizzle(method1: "setBounds:", + method2: #selector(UIView.cpk_setBounds)) + UIView.cpk_swizzle(method1: #selector(UIView.point(inside:with:)), + method2: #selector(UIView.cpk_point(inside:with:))) + + UILabel.cpk_swizzle(method1: #selector(setter: UILabel.text), + method2: #selector(UILabel.ner_setText(_:))) + + + UITextField.cpk_swizzle(method1: #selector(UITextField.textRect(forBounds:)), + method2: #selector(UITextField.cpk_textRect(forBounds:))) + UITextField.cpk_swizzle(method1: #selector(UITextField.editingRect(forBounds:)), + method2: #selector(UITextField.cpk_editingRect(forBounds:))) + + UITextView.cpk_swizzle(method1: "dealloc", method2: #selector(UITextView.cpk_deinit)) + } +} + extension UIApplication { open override var next: UIResponder? { - if !__flagForMethodSwizzle__ { - __flagForMethodSwizzle__ = true - - UIView.cpk_swizzle(method1: "setBounds:", - method2: #selector(UIView.cpk_setBounds)) - UIView.cpk_swizzle(method1: #selector(UIView.point(inside:with:)), - method2: #selector(UIView.cpk_point(inside:with:))) - - UILabel.cpk_swizzle(method1: #selector(setter: UILabel.text), - method2: #selector(UILabel.ner_setText(_:))) - - - UITextField.cpk_swizzle(method1: #selector(UITextField.textRect(forBounds:)), - method2: #selector(UITextField.cpk_textRect(forBounds:))) - UITextField.cpk_swizzle(method1: #selector(UITextField.editingRect(forBounds:)), - method2: #selector(UITextField.cpk_editingRect(forBounds:))) - - UITextView.cpk_swizzle(method1: "dealloc", method2: #selector(UITextView.cpk_deinit)) - } - + cpk_swizzleMethodsIfNeed() return super.next } } @@ -1901,7 +1904,7 @@ public class StaticRow: UIView { } public override class var layerClass: Swift.AnyClass { - return CATransformLayer.self + return CPKTransformLayer.self } func switchDidChange() {