mirror of
https://github.com/nerdycat/Cupcake.git
synced 2024-08-16 08:20:37 +03:00
compatible with Swift 4.2
This commit is contained in:
parent
52a8dd49b0
commit
5f9a85b73d
@ -175,7 +175,7 @@
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0820;
|
||||
LastUpgradeCheck = 0910;
|
||||
LastUpgradeCheck = 1000;
|
||||
ORGANIZATIONNAME = nerdycat;
|
||||
TargetAttributes = {
|
||||
841B2C6D1E7BC5900084B37C = {
|
||||
@ -285,6 +285,7 @@
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
@ -292,6 +293,7 @@
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
@ -340,6 +342,7 @@
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
@ -347,6 +350,7 @@
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
@ -385,7 +389,7 @@
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "nerdycat.Cupcake-Demo";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 4.0;
|
||||
SWIFT_VERSION = 4.2;
|
||||
TARGETED_DEVICE_FAMILY = 1;
|
||||
};
|
||||
name = Debug;
|
||||
@ -400,7 +404,7 @@
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "nerdycat.Cupcake-Demo";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 4.0;
|
||||
SWIFT_VERSION = 4.2;
|
||||
TARGETED_DEVICE_FAMILY = 1;
|
||||
};
|
||||
name = Release;
|
||||
|
Binary file not shown.
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0910"
|
||||
LastUpgradeVersion = "1000"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
@ -26,7 +26,6 @@
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
language = ""
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
@ -46,7 +45,6 @@
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
language = ""
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
|
@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
var window: UIWindow?
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||
|
||||
let sel = NSSelectorFromString("setContentInsetAdjustmentBehavior:")
|
||||
if UIScrollView().responds(to: sel) {
|
||||
|
@ -53,7 +53,7 @@ class AppStoreCell: UITableViewCell {
|
||||
HStack(indexLabel, iconView, 10, midStack, "<-->", 10, actionStack).embedIn(self.contentView, 10, 0, 10, 15)
|
||||
}
|
||||
|
||||
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
|
||||
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
||||
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
||||
setupUI()
|
||||
}
|
||||
@ -69,7 +69,7 @@ class AppStoreViewController: UITableViewController {
|
||||
var appList: Array<Dictionary<String, Any>>!
|
||||
|
||||
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
||||
return UITableViewAutomaticDimension
|
||||
return UITableView.automaticDimension
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
@ -92,7 +92,7 @@ class AppStoreViewController: UITableViewController {
|
||||
|
||||
self.tableView.estimatedRowHeight = 84
|
||||
self.tableView.register(AppStoreCell.self, forCellReuseIdentifier: "cell")
|
||||
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 34, 0)
|
||||
self.tableView.contentInset = UIEdgeInsets.init(top: 0, left: 0, bottom: 34, right: 0)
|
||||
|
||||
let path = Bundle.main.path(forResource: "appList", ofType: "plist")
|
||||
appList = NSArray(contentsOfFile: path!) as? Array<Dictionary<String, Any>>
|
||||
|
@ -114,7 +114,7 @@ class DashboardViewController: BaseViewController {
|
||||
class DashButton: UIButton {
|
||||
let subtitle: String!
|
||||
|
||||
override func setTitle(_ title: String?, for state: UIControlState) {
|
||||
override func setTitle(_ title: String?, for state: UIControl.State) {
|
||||
if state == .normal {
|
||||
let att = AttStr(
|
||||
AttStr(title).font("18").color("#181D42"), "\n",
|
||||
|
@ -1,7 +1,7 @@
|
||||
Pod::Spec.new do |s|
|
||||
|
||||
s.name = "Cupcake"
|
||||
s.version = "1.2.2"
|
||||
s.version = "1.2.3"
|
||||
s.summary = "An easy way to create and layout UI components for iOS."
|
||||
|
||||
s.description = <<-DESC
|
||||
|
@ -104,21 +104,36 @@ public extension NSMutableAttributedString {
|
||||
.underline(.styleDouble, "red") //double underline with red color
|
||||
...
|
||||
*/
|
||||
@discardableResult public func underline(_ style: NSUnderlineStyle = .styleSingle, _ color: Any? = nil) -> Self {
|
||||
#if swift(>=4.2)
|
||||
@discardableResult public func underline(_ style: NSUnderlineStyle = .single, _ color: Any? = nil) -> Self {
|
||||
var styles = NSNumber(value: style.rawValue)
|
||||
if style != .styleNone && style != .styleSingle && style != .styleThick && style != .styleDouble {
|
||||
styles = NSNumber(value: style.rawValue | NSUnderlineStyle.styleSingle.rawValue)
|
||||
if style != .none && style != .single && style != .thick && style != .double {
|
||||
styles = NSNumber(value: style.rawValue | NSUnderlineStyle.single.rawValue)
|
||||
}
|
||||
|
||||
cpk_addAttribute(name: "NSUnderline", value: styles)
|
||||
if let underlineColor = Color(color) {
|
||||
cpk_addAttribute(name: "NSUnderlineColor", value: underlineColor)
|
||||
}
|
||||
if let underlineColor = Color(color) { cpk_addAttribute(name: "NSUnderlineColor", value: underlineColor) }
|
||||
return self
|
||||
}
|
||||
#else
|
||||
@discardableResult public func underline(_ style: NSUnderlineStyle = .styleSingle, _ color: Any? = nil) -> Self {
|
||||
var styles = NSNumber(value: style.rawValue)
|
||||
if style != .styleNone && style != .styleSingle && style != .styleThick && style != .styleDouble {
|
||||
styles = NSNumber(value: style.rawValue | NSUnderlineStyle.styleSingle.rawValue)
|
||||
}
|
||||
|
||||
cpk_addAttribute(name: "NSUnderline", value: styles)
|
||||
if let underlineColor = Color(color) { cpk_addAttribute(name: "NSUnderlineColor", value: underlineColor) }
|
||||
return self
|
||||
}
|
||||
#endif
|
||||
|
||||
@discardableResult public func underline(_ color: Any) -> Self {
|
||||
#if swift(>=4.2)
|
||||
return underline(.single, color)
|
||||
#else
|
||||
return underline(.styleSingle, color)
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,10 +147,11 @@ public extension NSMutableAttributedString {
|
||||
.strikethrough(.styleDouble, "red") //double strikethrough with red color
|
||||
...
|
||||
*/
|
||||
@discardableResult public func strikethrough(_ style: NSUnderlineStyle = .styleSingle, _ color: Any? = nil) -> Self {
|
||||
#if swift(>=4.2)
|
||||
@discardableResult public func strikethrough(_ style: NSUnderlineStyle = .single, _ color: Any? = nil) -> Self {
|
||||
var styles = NSNumber(value: style.rawValue)
|
||||
if style != .styleNone && style != .styleSingle && style != .styleThick && style != .styleDouble {
|
||||
styles = NSNumber(value: style.rawValue | NSUnderlineStyle.styleSingle.rawValue)
|
||||
if style != .none && style != .single && style != .thick && style != .double {
|
||||
styles = NSNumber(value: style.rawValue | NSUnderlineStyle.single.rawValue)
|
||||
}
|
||||
|
||||
cpk_addAttribute(name: "NSStrikethrough", value: styles)
|
||||
@ -144,9 +160,27 @@ public extension NSMutableAttributedString {
|
||||
}
|
||||
return self
|
||||
}
|
||||
#else
|
||||
@discardableResult public func strikethrough(_ style: NSUnderlineStyle = .styleSingle, _ color: Any? = nil) -> Self {
|
||||
var styles = NSNumber(value: style.rawValue)
|
||||
if style != .styleNone && style != .styleSingle && style != .styleThick && style != .styleDouble {
|
||||
styles = NSNumber(value: style.rawValue | NSUnderlineStyle.styleSingle.rawValue)
|
||||
}
|
||||
|
||||
cpk_addAttribute(name: "NSStrikethrough", value: styles)
|
||||
if let strikethroughColor = Color(color) {
|
||||
cpk_addAttribute(name: "NSStrikethroughColor", value: strikethroughColor)
|
||||
}
|
||||
return self
|
||||
}
|
||||
#endif
|
||||
|
||||
@discardableResult public func strikethrough(_ color: Any) -> Self {
|
||||
#if swift(>=4.2)
|
||||
return strikethrough(.single, color)
|
||||
#else
|
||||
return strikethrough(.styleSingle, color)
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -185,10 +185,10 @@ public extension UIButton {
|
||||
self.cpkGap = spacing
|
||||
let halfGap = spacing / 2
|
||||
|
||||
self.titleEdgeInsets = UIEdgeInsetsMake(0, halfGap, 0, -halfGap)
|
||||
self.imageEdgeInsets = UIEdgeInsetsMake(0, -halfGap, 0, halfGap)
|
||||
self.titleEdgeInsets = UIEdgeInsetsMake_(0, halfGap, 0, -halfGap)
|
||||
self.imageEdgeInsets = UIEdgeInsetsMake_(0, -halfGap, 0, halfGap)
|
||||
|
||||
var insets = self.cpkInsets ?? UIEdgeInsetsMake(0, 0, 0, 0)
|
||||
var insets = self.cpkInsets ?? UIEdgeInsetsMake_(0, 0, 0, 0)
|
||||
insets.left += halfGap
|
||||
insets.right += halfGap
|
||||
self.contentEdgeInsets = insets
|
||||
|
@ -33,7 +33,7 @@ public class CPKStackView: UIView {
|
||||
|
||||
private var _alignment: CPKStackAlignment = .left
|
||||
private var _spacing: CGFloat = 0
|
||||
private var _axis: UILayoutConstraintAxis = .horizontal
|
||||
private var _axis: UILayoutConstraintAxis_ = .horizontal
|
||||
private var _headAttachSpace: CGFloat?
|
||||
|
||||
public private(set) var arrangedSubviews = [UIView]()
|
||||
@ -49,7 +49,7 @@ public class CPKStackView: UIView {
|
||||
set { if _spacing != newValue { _spacing = newValue; spacingDidChange() } }
|
||||
}
|
||||
|
||||
public var axis: UILayoutConstraintAxis {
|
||||
public var axis: UILayoutConstraintAxis_ {
|
||||
get { return _axis }
|
||||
set { if _axis != newValue { _axis = newValue; axisDidChange() } }
|
||||
}
|
||||
@ -82,9 +82,16 @@ public class CPKStackView: UIView {
|
||||
view.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addObserver(self, forKeyPath: "hidden", options: [.new, .old], context: nil)
|
||||
|
||||
#if swift(>=4.2)
|
||||
if view.layoutMargins == UIEdgeInsetsMake_(8, 8, 8, 8) {
|
||||
view.layoutMargins = UIEdgeInsets.zero
|
||||
}
|
||||
#else
|
||||
if UIEdgeInsetsEqualToEdgeInsets(view.layoutMargins, UIEdgeInsetsMake(8, 8, 8, 8)) {
|
||||
view.layoutMargins = UIEdgeInsets.zero
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if !view.isHidden {
|
||||
addAndActivateConstraintsForView(at: index)
|
||||
@ -148,7 +155,7 @@ public class CPKStackView: UIView {
|
||||
}
|
||||
|
||||
public override func sizeThatFits(_ size: CGSize) -> CGSize {
|
||||
return systemLayoutSizeFitting(UILayoutFittingCompressedSize)
|
||||
return systemLayoutSizeFitting(UILayoutFittingCompressedSize_)
|
||||
}
|
||||
|
||||
|
||||
@ -256,7 +263,7 @@ public class CPKStackView: UIView {
|
||||
@discardableResult
|
||||
private func addAlignmentConstraint(at index: Int) -> [NSLayoutConstraint] {
|
||||
var newConstraints = [NSLayoutConstraint]()
|
||||
var att = NSLayoutAttribute.notAnAttribute
|
||||
var att = NSLayoutAttribute_.notAnAttribute
|
||||
|
||||
if self.alignment == .fill {
|
||||
|
||||
@ -337,7 +344,7 @@ public class CPKStackView: UIView {
|
||||
newConstraints.append(makeConstraint(index, .topMargin, .equal, -1, .topMargin, enclosurePriority))
|
||||
newConstraints.append(makeConstraint(index, .topMargin, .greaterThanOrEqual, -1, .topMargin, 1000))
|
||||
|
||||
var att: NSLayoutAttribute = .bottomMargin
|
||||
var att: NSLayoutAttribute_ = .bottomMargin
|
||||
if self.alignment == .baseline {
|
||||
att = .lastBaseline
|
||||
}
|
||||
@ -391,8 +398,8 @@ public class CPKStackView: UIView {
|
||||
return nil
|
||||
}
|
||||
|
||||
var att1 = NSLayoutAttribute.notAnAttribute
|
||||
var att2 = NSLayoutAttribute.notAnAttribute
|
||||
var att1 = NSLayoutAttribute_.notAnAttribute
|
||||
var att2 = NSLayoutAttribute_.notAnAttribute
|
||||
|
||||
if self.axis == .vertical {
|
||||
att1 = (item1 == self ? .topMargin : .bottomMargin)
|
||||
@ -524,7 +531,7 @@ public class CPKStackView: UIView {
|
||||
}
|
||||
|
||||
if !hasConstraint {
|
||||
let att: NSLayoutAttribute = (self.axis == .vertical ? .height : .width)
|
||||
let att: NSLayoutAttribute_ = (self.axis == .vertical ? .height : .width)
|
||||
let c = makeConstraint(i, att, .equal, index, att, 1, 0, kSpringPriority)
|
||||
self.springConstraints.append(c)
|
||||
newConstraints.append(c)
|
||||
@ -559,10 +566,10 @@ public class CPKStackView: UIView {
|
||||
|
||||
//MARK: Utils
|
||||
private func makeConstraint(_ index1: Int,
|
||||
_ att1: NSLayoutAttribute,
|
||||
_ relation: NSLayoutRelation,
|
||||
_ att1: NSLayoutAttribute_,
|
||||
_ relation: NSLayoutRelation_,
|
||||
_ index2: Int,
|
||||
_ att2: NSLayoutAttribute,
|
||||
_ att2: NSLayoutAttribute_,
|
||||
_ multiplier: CGFloat,
|
||||
_ constant: CGFloat,
|
||||
_ priority: UILayoutPriority) -> NSLayoutConstraint {
|
||||
@ -583,10 +590,10 @@ public class CPKStackView: UIView {
|
||||
}
|
||||
|
||||
private func makeConstraint(_ index1: Int,
|
||||
_ att1: NSLayoutAttribute,
|
||||
_ relation: NSLayoutRelation,
|
||||
_ att1: NSLayoutAttribute_,
|
||||
_ relation: NSLayoutRelation_,
|
||||
_ index2: Int,
|
||||
_ att2: NSLayoutAttribute,
|
||||
_ att2: NSLayoutAttribute_,
|
||||
_ priority: UILayoutPriority) -> NSLayoutConstraint {
|
||||
|
||||
return makeConstraint(index1, att1, relation, index2, att2, 1, 0, priority)
|
||||
@ -675,9 +682,9 @@ class CPKTransformLayer: CATransformLayer {
|
||||
|
||||
|
||||
public class StackSpring: UIView {
|
||||
private var _axis: UILayoutConstraintAxis = .horizontal
|
||||
private var _axis: UILayoutConstraintAxis_ = .horizontal
|
||||
|
||||
fileprivate var axis: UILayoutConstraintAxis {
|
||||
fileprivate var axis: UILayoutConstraintAxis_ {
|
||||
get { return _axis }
|
||||
set {
|
||||
if _axis != newValue {
|
||||
|
@ -41,7 +41,7 @@ public func Font(_ any: Any) -> UIFont {
|
||||
}
|
||||
|
||||
let value = "UICTFontTextStyle" + string.capitalized
|
||||
return UIFont.preferredFont(forTextStyle: UIFontTextStyle(rawValue: value))
|
||||
return UIFont.preferredFont(forTextStyle: UIFontTextStyle_(rawValue: value))
|
||||
}
|
||||
|
||||
return UIFont.systemFont(ofSize: CPKFloat(any))
|
||||
|
@ -48,7 +48,7 @@ public extension UIImageView {
|
||||
.mode(.center)
|
||||
...
|
||||
*/
|
||||
@objc @discardableResult public func mode(_ contentMode: UIViewContentMode) -> Self {
|
||||
@objc @discardableResult public func mode(_ contentMode: UIViewContentMode_) -> Self {
|
||||
self.contentMode = contentMode
|
||||
return self
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ public extension StaticRow {
|
||||
.style(.value2)
|
||||
...
|
||||
*/
|
||||
@discardableResult public func style(_ style: UITableViewCellStyle) -> Self {
|
||||
@discardableResult public func style(_ style: UITableViewCellStyle_) -> Self {
|
||||
self.cellStyle = style
|
||||
return self
|
||||
}
|
||||
|
@ -121,11 +121,10 @@ public extension StylesMaker {
|
||||
return addStyle(key: #function, value: any)
|
||||
}
|
||||
|
||||
@discardableResult public func mode(_ contentMode: UIViewContentMode) -> Self {
|
||||
@discardableResult public func mode(_ contentMode: UIViewContentMode_) -> Self {
|
||||
return addStyle(key: #function, value: contentMode)
|
||||
}
|
||||
|
||||
|
||||
//Button
|
||||
@discardableResult public func highColor(_ any: Any) -> Self {
|
||||
return addStyle(key: #function, value: any)
|
||||
@ -173,7 +172,7 @@ public extension StylesMaker {
|
||||
return addStyle(key: #function, value: returnKeyType)
|
||||
}
|
||||
|
||||
@discardableResult public func clearMode(_ clearButtonMode: UITextFieldViewMode) -> Self {
|
||||
@discardableResult public func clearMode(_ clearButtonMode: UITextFieldViewMode_) -> Self {
|
||||
return addStyle(key: #function, value: clearButtonMode)
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ public extension UITextField {
|
||||
.clearMode(.always)
|
||||
...
|
||||
*/
|
||||
@objc @discardableResult public func clearMode(_ clearButtonMode: UITextFieldViewMode) -> Self {
|
||||
@objc @discardableResult public func clearMode(_ clearButtonMode: UITextFieldViewMode_) -> Self {
|
||||
self.clearButtonMode = clearButtonMode
|
||||
return self
|
||||
}
|
||||
|
@ -21,6 +21,64 @@ import UIKit.UIGestureRecognizerSubclass
|
||||
|
||||
|
||||
|
||||
#if swift(>=4.2)
|
||||
|
||||
public typealias UITextFieldViewMode_ = UITextField.ViewMode
|
||||
public typealias UITableViewStyle_ = UITableView.Style
|
||||
public typealias UITableViewCellStyle_ = UITableViewCell.CellStyle
|
||||
public typealias UITableViewCellAccessoryType_ = UITableViewCell.AccessoryType
|
||||
public typealias UIViewContentMode_ = UIView.ContentMode
|
||||
public typealias UILayoutConstraintAxis_ = NSLayoutConstraint.Axis
|
||||
|
||||
typealias UIFontTextStyle_ = UIFont.TextStyle
|
||||
typealias NSLayoutAttribute_ = NSLayoutConstraint.Attribute
|
||||
typealias NSLayoutRelation_ = NSLayoutConstraint.Relation
|
||||
typealias NSAttributedStringKey_ = NSAttributedString.Key
|
||||
typealias UIAlertActionStyle_ = UIAlertAction.Style
|
||||
typealias UIAlertControllerStyle_ = UIAlertController.Style
|
||||
|
||||
private let UITableViewAutomaticDimension_ = UITableView.automaticDimension
|
||||
let UILayoutFittingCompressedSize_ = UIView.layoutFittingCompressedSize
|
||||
|
||||
func UIEdgeInsetsMake_(_ top: CGFloat, _ left: CGFloat, _ bottom: CGFloat, _ right: CGFloat) -> UIEdgeInsets {
|
||||
return UIEdgeInsets.init(top: top, left: left, bottom: bottom, right: right)
|
||||
}
|
||||
|
||||
func UIEdgeInsetsInsetRect_(_ rect: CGRect, _ insets: UIEdgeInsets) -> CGRect {
|
||||
return rect.inset(by: insets)
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
public typealias UITextFieldViewMode_ = UITextFieldViewMode
|
||||
public typealias UITableViewStyle_ = UITableViewStyle
|
||||
public typealias UITableViewCellStyle_ = UITableViewCellStyle
|
||||
public typealias UITableViewCellAccessoryType_ = UITableViewCellAccessoryType
|
||||
public typealias UIViewContentMode_ = UIViewContentMode
|
||||
public typealias UILayoutConstraintAxis_ = UILayoutConstraintAxis
|
||||
|
||||
typealias UIFontTextStyle_ = UIFontTextStyle
|
||||
typealias NSLayoutAttribute_ = NSLayoutAttribute
|
||||
typealias NSLayoutRelation_ = NSLayoutRelation
|
||||
typealias NSAttributedStringKey_ = NSAttributedStringKey
|
||||
typealias UIAlertActionStyle_ = UIAlertActionStyle
|
||||
typealias UIAlertControllerStyle_ = UIAlertControllerStyle
|
||||
|
||||
private let UITableViewAutomaticDimension_ = UITableViewAutomaticDimension
|
||||
let UILayoutFittingCompressedSize_ = UILayoutFittingCompressedSize
|
||||
|
||||
func UIEdgeInsetsMake_(_ top: CGFloat, _ left: CGFloat, _ bottom: CGFloat, _ right: CGFloat) -> UIEdgeInsets {
|
||||
return UIEdgeInsetsMake(top, left, bottom, right)
|
||||
}
|
||||
|
||||
func UIEdgeInsetsInsetRect_(_ rect: CGRect, _ insets: UIEdgeInsets) -> CGRect {
|
||||
return UIEdgeInsetsInsetRect(rect, insets)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//MARK: Utils
|
||||
@ -117,29 +175,29 @@ func cpk_imageHasAlphaChannel(_ image: UIImage) -> Bool {
|
||||
|
||||
func cpk_edgeInsetsFromArray(_ insetArray: [CGFloat]) -> UIEdgeInsets {
|
||||
if insetArray.count == 0 {
|
||||
return UIEdgeInsetsMake(0, 0, 0, 0)
|
||||
return UIEdgeInsetsMake_(0, 0, 0, 0)
|
||||
|
||||
} else if insetArray.count == 1 {
|
||||
let m1 = insetArray[0]
|
||||
return UIEdgeInsetsMake(m1, m1, m1, m1)
|
||||
return UIEdgeInsetsMake_(m1, m1, m1, m1)
|
||||
|
||||
} else if insetArray.count == 2 {
|
||||
let m1 = insetArray[0]
|
||||
let m2 = insetArray[1]
|
||||
return UIEdgeInsetsMake(m1, m2, m1, m2)
|
||||
return UIEdgeInsetsMake_(m1, m2, m1, m2)
|
||||
|
||||
} else if insetArray.count == 3 {
|
||||
let m1 = insetArray[0]
|
||||
let m2 = insetArray[1]
|
||||
let m3 = insetArray[2]
|
||||
return UIEdgeInsetsMake(m1, m2, 0, m3)
|
||||
return UIEdgeInsetsMake_(m1, m2, 0, m3)
|
||||
|
||||
} else {
|
||||
let m1 = insetArray[0]
|
||||
let m2 = insetArray[1]
|
||||
let m3 = insetArray[2]
|
||||
let m4 = insetArray[3]
|
||||
return UIEdgeInsetsMake(m1, m2, m3, m4)
|
||||
return UIEdgeInsetsMake_(m1, m2, m3, m4)
|
||||
}
|
||||
}
|
||||
|
||||
@ -659,7 +717,7 @@ extension NSMutableAttributedString {
|
||||
|
||||
func cpk_addAttribute(_ name: String, value: Any, range: NSRange) {
|
||||
#if swift(>=4.0)
|
||||
addAttribute(NSAttributedStringKey(rawValue: name), value: value, range: range)
|
||||
addAttribute(NSAttributedStringKey_(rawValue: name), value: value, range: range)
|
||||
#else
|
||||
addAttribute(name, value: value, range: range)
|
||||
#endif
|
||||
@ -688,7 +746,7 @@ extension NSMutableAttributedString {
|
||||
let indexSets = NSMutableIndexSet(indexesIn: range)
|
||||
|
||||
#if swift(>=4.0)
|
||||
enumerateAttribute(NSAttributedStringKey(rawValue: name),
|
||||
enumerateAttribute(NSAttributedStringKey_(rawValue: name),
|
||||
in: range,
|
||||
options: NSAttributedString.EnumerationOptions(rawValue: 0))
|
||||
{ (value, range, stop) in
|
||||
@ -785,7 +843,7 @@ extension UIView {
|
||||
|
||||
@objc func cpk_point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
||||
if let insets = self.cpkTouchInsets {
|
||||
let rect = UIEdgeInsetsInsetRect(self.bounds, insets)
|
||||
let rect = UIEdgeInsetsInsetRect_(self.bounds, insets)
|
||||
return rect.contains(point)
|
||||
} else {
|
||||
return self.cpk_point(inside: point, with: event)
|
||||
@ -921,7 +979,7 @@ extension UITextField {
|
||||
}
|
||||
|
||||
var cpkPadding: UIEdgeInsets {
|
||||
get { return cpk_associatedObjectFor(key: #function) as? UIEdgeInsets ?? UIEdgeInsetsMake(0, 0, 0, 0) }
|
||||
get { return cpk_associatedObjectFor(key: #function) as? UIEdgeInsets ?? UIEdgeInsetsMake_(0, 0, 0, 0) }
|
||||
set { cpk_setAssociated(object: newValue, forKey: #function) }
|
||||
}
|
||||
|
||||
@ -937,12 +995,12 @@ extension UITextField {
|
||||
|
||||
@objc public func cpk_textRect(forBounds bounds: CGRect) -> CGRect {
|
||||
let rect = self.cpk_textRect(forBounds: bounds)
|
||||
return UIEdgeInsetsInsetRect(rect, self.cpkPadding)
|
||||
return UIEdgeInsetsInsetRect_(rect, self.cpkPadding)
|
||||
}
|
||||
|
||||
@objc public func cpk_editingRect(forBounds bounds: CGRect) -> CGRect {
|
||||
let rect = cpk_editingRect(forBounds: bounds)
|
||||
return UIEdgeInsetsInsetRect(rect, self.cpkPadding)
|
||||
return UIEdgeInsetsInsetRect_(rect, self.cpkPadding)
|
||||
}
|
||||
|
||||
private func cpk_watchTextChange() {
|
||||
@ -1009,9 +1067,9 @@ extension UILayoutPriority : ExpressibleByIntegerLiteral, ExpressibleByFloatLite
|
||||
self = UILayoutPriority(rawValue: value)
|
||||
}
|
||||
}
|
||||
extension NSAttributedStringKey : ExpressibleByStringLiteral {
|
||||
extension NSAttributedStringKey_ : ExpressibleByStringLiteral {
|
||||
public init(stringLiteral value: String) {
|
||||
self = NSAttributedStringKey(rawValue: value)
|
||||
self = NSAttributedStringKey_(rawValue: value)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1065,15 +1123,15 @@ public class AlertMaker {
|
||||
var cpkTitle: Any?
|
||||
var cpkMessage: Any?
|
||||
var cpkTint: Any?
|
||||
var cpkStyle: UIAlertControllerStyle
|
||||
var cpkStyle: UIAlertControllerStyle_
|
||||
|
||||
private var actions = [UIAlertAction]()
|
||||
|
||||
init(style: UIAlertControllerStyle) {
|
||||
init(style: UIAlertControllerStyle_) {
|
||||
self.cpkStyle = style
|
||||
}
|
||||
|
||||
func cpk_addAction(style: UIAlertActionStyle, title: Any, handler: (()->())? ) {
|
||||
func cpk_addAction(style: UIAlertActionStyle_, title: Any, handler: (()->())? ) {
|
||||
var titleString: String?
|
||||
var titleColor: UIColor?
|
||||
|
||||
@ -1173,7 +1231,7 @@ public class AlertMaker {
|
||||
|
||||
public class ConsAtts: NSObject {
|
||||
@discardableResult
|
||||
func addAttributes(_ attributes: NSLayoutAttribute...) -> Cons {
|
||||
func addAttributes(_ attributes: NSLayoutAttribute_...) -> Cons {
|
||||
//only for override
|
||||
return Cons(firstItem: UIView())
|
||||
}
|
||||
@ -1184,10 +1242,10 @@ public class Cons: ConsAtts {
|
||||
private var secondItem: UIView?
|
||||
private var secondItemReferToSuperview = false
|
||||
|
||||
var relation = NSLayoutRelation.equal
|
||||
var relation = NSLayoutRelation_.equal
|
||||
|
||||
var firstItemAttributes = [NSLayoutAttribute]()
|
||||
var secondItemAttributes = [NSLayoutAttribute]()
|
||||
var firstItemAttributes = [NSLayoutAttribute_]()
|
||||
var secondItemAttributes = [NSLayoutAttribute_]()
|
||||
|
||||
var multiplierValues = [CGFloat]()
|
||||
var constantValues = [CGFloat]()
|
||||
@ -1202,7 +1260,7 @@ public class Cons: ConsAtts {
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
override func addAttributes(_ attributes: NSLayoutAttribute...) -> Cons {
|
||||
override func addAttributes(_ attributes: NSLayoutAttribute_...) -> Cons {
|
||||
for att in attributes {
|
||||
if secondItem == nil && !secondItemReferToSuperview {
|
||||
firstItemAttributes.append(att)
|
||||
@ -1294,7 +1352,7 @@ public class Cons: ConsAtts {
|
||||
return priority
|
||||
}
|
||||
|
||||
private func secondItemValue(att1: NSLayoutAttribute) -> UIView? {
|
||||
private func secondItemValue(att1: NSLayoutAttribute_) -> UIView? {
|
||||
var secondItem = self.secondItem
|
||||
if (secondItem == nil && att1 != .width && att1 != .height) {
|
||||
secondItem = self.firstItem.superview
|
||||
@ -1358,7 +1416,7 @@ public class ConsMaker: ConsAtts {
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
override func addAttributes(_ attributes: NSLayoutAttribute...) -> Cons {
|
||||
override func addAttributes(_ attributes: NSLayoutAttribute_...) -> Cons {
|
||||
let c = Cons(firstItem: firstItem)
|
||||
cons.append(c)
|
||||
|
||||
@ -1806,7 +1864,7 @@ public class StylesMaker: NSObject {
|
||||
|
||||
} else if key == "mode" {
|
||||
if let imageView = view as? UIImageView {
|
||||
imageView.mode(value as! UIViewContentMode)
|
||||
imageView.mode(value as! UIViewContentMode_)
|
||||
}
|
||||
|
||||
} else if key == "reversed" {
|
||||
@ -1845,7 +1903,7 @@ public class StylesMaker: NSObject {
|
||||
|
||||
else if key == "clearMode" {
|
||||
if let textField = view as? UITextField {
|
||||
textField.clearMode(value as! UITextFieldViewMode)
|
||||
textField.clearMode(value as! UITextFieldViewMode_)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1953,7 +2011,7 @@ public class StaticTableView: UITableView, UITableViewDelegate, UITableViewDataS
|
||||
var detailFont: Any?
|
||||
var detailColor: Any?
|
||||
|
||||
public init(sectionsOrRows: [Any], style: UITableViewStyle) {
|
||||
public init(sectionsOrRows: [Any], style: UITableViewStyle_) {
|
||||
super.init(frame: CGRect.zero, style: style)
|
||||
self.estimatedRowHeight = 44
|
||||
self.estimatedSectionHeaderHeight = 0
|
||||
@ -2085,7 +2143,7 @@ public class StaticTableView: UITableView, UITableViewDelegate, UITableViewDataS
|
||||
return height == 0 ? 0.001 : height
|
||||
}
|
||||
|
||||
return UITableViewAutomaticDimension
|
||||
return UITableViewAutomaticDimension_
|
||||
}
|
||||
|
||||
public func tableView(_ tableView: UITableView, heightForFooterInSection sectionIndex: Int) -> CGFloat {
|
||||
@ -2098,7 +2156,7 @@ public class StaticTableView: UITableView, UITableViewDelegate, UITableViewDataS
|
||||
return height == 0 ? 0.001 : height
|
||||
}
|
||||
|
||||
return UITableViewAutomaticDimension
|
||||
return UITableViewAutomaticDimension_
|
||||
}
|
||||
|
||||
public func tableView(_ tableView: UITableView, titleForHeaderInSection sectionIndex: Int) -> String? {
|
||||
@ -2254,7 +2312,7 @@ public class StaticRow: UIView {
|
||||
var cellHeight: CGFloat?
|
||||
var separatorIndent: CGFloat?
|
||||
|
||||
var cellStyle: UITableViewCellStyle = .default
|
||||
var cellStyle: UITableViewCellStyle_ = .default
|
||||
|
||||
var onClickHandler: ((StaticRow)->())?
|
||||
var onButtonHandler: ((StaticRow)->())?
|
||||
@ -2360,8 +2418,8 @@ public class StaticRow: UIView {
|
||||
|
||||
if let indent = lineIndent() {
|
||||
cell.preservesSuperviewLayoutMargins = false
|
||||
cell.layoutMargins = UIEdgeInsetsMake(0, 0, 0, 0)
|
||||
cell.separatorInset = UIEdgeInsetsMake(0, indent, 0, 0)
|
||||
cell.layoutMargins = UIEdgeInsetsMake_(0, 0, 0, 0)
|
||||
cell.separatorInset = UIEdgeInsetsMake_(0, indent, 0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2374,7 +2432,7 @@ public class StaticRow: UIView {
|
||||
rowHeight = height
|
||||
}
|
||||
|
||||
return rowHeight >= 0 ? rowHeight : UITableViewAutomaticDimension
|
||||
return rowHeight >= 0 ? rowHeight : UITableViewAutomaticDimension_
|
||||
}
|
||||
|
||||
fileprivate func lineIndent() -> CGFloat? {
|
||||
@ -2420,7 +2478,7 @@ public class StaticRow: UIView {
|
||||
|
||||
|
||||
extension CPKTableViewCellAccessoryType {
|
||||
public func accessoryType() -> (UITableViewCellAccessoryType, UIView?) {
|
||||
public func accessoryType() -> (UITableViewCellAccessoryType_, UIView?) {
|
||||
switch self {
|
||||
case .none: return (.none, nil)
|
||||
case .disclosureIndicator: return (.disclosureIndicator, nil)
|
||||
@ -2550,7 +2608,7 @@ fileprivate class UITextViewPlaceholder: UILabel {
|
||||
self.font = font
|
||||
self.textAlignment = textView.textAlignment
|
||||
|
||||
var rect = UIEdgeInsetsInsetRect(textView.bounds, textView.textContainerInset)
|
||||
var rect = UIEdgeInsetsInsetRect_(textView.bounds, textView.textContainerInset)
|
||||
rect = rect.insetBy(dx: textView.textContainer.lineFragmentPadding, dy: 0)
|
||||
rect.size.height = min(rect.height, self.sizeThatFits(CGSize(width: rect.width, height: 0)).height)
|
||||
self.frame = rect
|
||||
@ -2594,14 +2652,14 @@ extension UITextView {
|
||||
}
|
||||
|
||||
private func cpk_watchTextChange() {
|
||||
NotificationCenter.default.removeObserver(self,
|
||||
name: NSNotification.Name.UITextViewTextDidChange,
|
||||
object: self)
|
||||
#if swift(>=4.2)
|
||||
let name = UITextView.textDidChangeNotification
|
||||
#else
|
||||
let name = NSNotification.Name.UITextViewTextDidChange
|
||||
#endif
|
||||
|
||||
NotificationCenter.default.addObserver(self,
|
||||
selector: #selector(cpk_textDidChange),
|
||||
name: NSNotification.Name.UITextViewTextDidChange,
|
||||
object: self)
|
||||
NotificationCenter.default.removeObserver(self, name: name, object: self)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(cpk_textDidChange), name: name, object: self)
|
||||
}
|
||||
|
||||
@objc func cpk_textDidChange() {
|
||||
|
Loading…
Reference in New Issue
Block a user