fixed bugs on iOS 8

This commit is contained in:
caiyuanpeng 2017-10-10 17:17:35 +08:00
parent b5fef0e338
commit ec5c88e7b3
11 changed files with 39 additions and 22 deletions

View File

@ -1,7 +1,7 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "Cupcake" 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.summary = "An easy way to create and layout UI components for iOS."
s.description = <<-DESC s.description = <<-DESC

View File

@ -26,10 +26,12 @@ import UIKit
*/ */
public var Alert: AlertMaker { public var Alert: AlertMaker {
cpk_swizzleMethodsIfNeed()
return AlertMaker(style: .alert) return AlertMaker(style: .alert)
} }
public var ActionSheet: AlertMaker { public var ActionSheet: AlertMaker {
cpk_swizzleMethodsIfNeed()
return AlertMaker(style: .actionSheet) return AlertMaker(style: .actionSheet)
} }

View File

@ -9,6 +9,7 @@
import UIKit import UIKit
public var Button: UIButton { public var Button: UIButton {
cpk_swizzleMethodsIfNeed()
let button = UIButton() let button = UIButton()
cpk_higherHuggingAndResistance(forView: button) cpk_higherHuggingAndResistance(forView: button)
return button return button

View File

@ -9,6 +9,7 @@
import UIKit import UIKit
public var ImageView: UIImageView { public var ImageView: UIImageView {
cpk_swizzleMethodsIfNeed()
let imageView = UIImageView() let imageView = UIImageView()
cpk_higherHuggingAndResistance(forView: imageView) cpk_higherHuggingAndResistance(forView: imageView)
return imageView return imageView

View File

@ -9,6 +9,7 @@
import UIKit import UIKit
public var Label: UILabel { public var Label: UILabel {
cpk_swizzleMethodsIfNeed()
let label = UILabel() let label = UILabel()
return label return label
} }

View File

@ -68,6 +68,7 @@ public enum CPKStackAlignment : Int {
*/ */
public func HStack(_ items: Any...) -> CPKStackView { public func HStack(_ items: Any...) -> CPKStackView {
cpk_swizzleMethodsIfNeed()
let stack = CPKStackView() let stack = CPKStackView()
stack.axis = .horizontal stack.axis = .horizontal
stack.alignment = .center stack.alignment = .center
@ -76,6 +77,7 @@ public func HStack(_ items: Any...) -> CPKStackView {
} }
public func VStack(_ items: Any...) -> CPKStackView { public func VStack(_ items: Any...) -> CPKStackView {
cpk_swizzleMethodsIfNeed()
let stack = CPKStackView() let stack = CPKStackView()
stack.axis = .vertical stack.axis = .vertical
stack.alignment = .left stack.alignment = .left

View File

@ -36,20 +36,24 @@ import UIKit
*/ */
public func PlainTable(_ sectionsOrRows: Any...) -> StaticTableView { public func PlainTable(_ sectionsOrRows: Any...) -> StaticTableView {
cpk_swizzleMethodsIfNeed()
let tableView = StaticTableView(sectionsOrRows: sectionsOrRows, style: .plain) let tableView = StaticTableView(sectionsOrRows: sectionsOrRows, style: .plain)
tableView.tableFooterView = UIView() tableView.tableFooterView = UIView()
return tableView return tableView
} }
public func GroupTable(_ sectionsOrRows: Any...) -> StaticTableView { public func GroupTable(_ sectionsOrRows: Any...) -> StaticTableView {
cpk_swizzleMethodsIfNeed()
return StaticTableView(sectionsOrRows: sectionsOrRows, style: .grouped) return StaticTableView(sectionsOrRows: sectionsOrRows, style: .grouped)
} }
public func Section(_ rowsOrStrings: Any...) -> StaticSection { public func Section(_ rowsOrStrings: Any...) -> StaticSection {
cpk_swizzleMethodsIfNeed()
return StaticSection(rowsOrStrings: rowsOrStrings) return StaticSection(rowsOrStrings: rowsOrStrings)
} }
public var Row: StaticRow { public var Row: StaticRow {
cpk_swizzleMethodsIfNeed()
return StaticRow() return StaticRow()
} }

View File

@ -9,6 +9,7 @@
import UIKit import UIKit
public var TextField: UITextField { public var TextField: UITextField {
cpk_swizzleMethodsIfNeed()
let textField = UITextField() let textField = UITextField()
textField.enablesReturnKeyAutomatically = true textField.enablesReturnKeyAutomatically = true
textField.returnKeyType = .done textField.returnKeyType = .done

View File

@ -9,6 +9,7 @@
import UIKit import UIKit
public var TextView: UITextView { public var TextView: UITextView {
cpk_swizzleMethodsIfNeed()
return UITextView().font(17) return UITextView().font(17)
} }

View File

@ -9,6 +9,7 @@
import UIKit import UIKit
public var View: UIView { public var View: UIView {
cpk_swizzleMethodsIfNeed()
let view = UIView() let view = UIView()
return view return view
} }

View File

@ -601,28 +601,31 @@ extension NSMutableAttributedString {
fileprivate var __flagForMethodSwizzle__: Bool = false 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 { extension UIApplication {
open override var next: UIResponder? { open override var next: UIResponder? {
if !__flagForMethodSwizzle__ { cpk_swizzleMethodsIfNeed()
__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))
}
return super.next return super.next
} }
} }
@ -1901,7 +1904,7 @@ public class StaticRow: UIView {
} }
public override class var layerClass: Swift.AnyClass { public override class var layerClass: Swift.AnyClass {
return CATransformLayer.self return CPKTransformLayer.self
} }
func switchDidChange() { func switchDidChange() {