diff --git a/Cupcake-Demo/Cupcake-Demo.xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate b/Cupcake-Demo/Cupcake-Demo.xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate index 4e68187..7827c64 100644 Binary files a/Cupcake-Demo/Cupcake-Demo.xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate and b/Cupcake-Demo/Cupcake-Demo.xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Cupcake.podspec b/Cupcake.podspec index 406f70b..cbad37a 100644 --- a/Cupcake.podspec +++ b/Cupcake.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Cupcake" - s.version = "0.1.2" + s.version = "1.0.0" s.summary = "An easy way to create and layout UI components for iOS." s.description = <<-DESC diff --git a/Cupcake/AttStr.swift b/Cupcake/AttStr.swift index 3503003..35d4198 100644 --- a/Cupcake/AttStr.swift +++ b/Cupcake/AttStr.swift @@ -42,7 +42,7 @@ public func AttStr(_ objects: Any?...) -> NSMutableAttributedString { } -extension NSMutableAttributedString { +public extension NSMutableAttributedString { /** * NSFontAttributeName @@ -145,8 +145,7 @@ extension NSMutableAttributedString { return self } - @discardableResult - public func strikethrough(_ color: Any) -> Self { + @discardableResult public func strikethrough(_ color: Any) -> Self { return strikethrough(.styleSingle, color) } @@ -158,8 +157,7 @@ extension NSMutableAttributedString { .stroke(1) .stroke(-4, "red") */ - @discardableResult - public func stroke(_ width: CGFloat, _ color: Any? = nil) -> Self { + @discardableResult public func stroke(_ width: CGFloat, _ color: Any? = nil) -> Self { cpk_addAttribute(name: NSStrokeWidthAttributeName, value: width) if let strokeColor = Color(color) { cpk_addAttribute(name: NSStrokeColorAttributeName, value: strokeColor) @@ -173,8 +171,7 @@ extension NSMutableAttributedString { .oblique(0.3) .oblique(-0.3) */ - @discardableResult - public func oblique(_ value: CGFloat) -> Self { + @discardableResult public func oblique(_ value: CGFloat) -> Self { cpk_addAttribute(name: NSObliquenessAttributeName, value: value) return self } @@ -185,8 +182,7 @@ extension NSMutableAttributedString { .offset(20) .offset(-20) */ - @discardableResult - public func offset(_ offset: CGFloat) -> Self { + @discardableResult public func offset(_ offset: CGFloat) -> Self { cpk_addAttribute(name: NSBaselineOffsetAttributeName, value: offset) return self } @@ -198,8 +194,7 @@ extension NSMutableAttributedString { .link("http://www.google.com") .link() //mark as link for UILabel */ - @discardableResult - public func link(_ url: String? = nil) -> Self { + @discardableResult public func link(_ url: String? = nil) -> Self { if let urlString = url { cpk_addAttribute(name: NSLinkAttributeName, value: urlString) } else { @@ -213,8 +208,7 @@ extension NSMutableAttributedString { * Usages: .lineGap(10) */ - @discardableResult - public func lineGap(_ spacing: CGFloat) -> Self { + @discardableResult public func lineGap(_ spacing: CGFloat) -> Self { cpk_addParagraphAttribute(key: "lineSpacing", value: spacing) return self } @@ -224,8 +218,7 @@ extension NSMutableAttributedString { * Usages: .indent(20) */ - @discardableResult - public func indent(_ headIntent: CGFloat) -> Self { + @discardableResult public func indent(_ headIntent: CGFloat) -> Self { cpk_addParagraphAttribute(key: "firstLineHeadIndent", value: headIntent) return self } @@ -237,8 +230,7 @@ extension NSMutableAttributedString { .align(.justified) ... */ - @discardableResult - public func align(_ alignment: NSTextAlignment) -> Self { + @discardableResult public func align(_ alignment: NSTextAlignment) -> Self { cpk_addParagraphAttribute(key: "alignment", value: NSNumber(value: alignment.rawValue)) return self } @@ -261,8 +253,7 @@ extension NSMutableAttributedString { * .select("pattern") is just the shorthand of .select(.match("pattern")) */ - @discardableResult - public func select(_ optionOrStringLiterals: AttStrSelectionOptions...) -> Self { + @discardableResult public func select(_ optionOrStringLiterals: AttStrSelectionOptions...) -> Self { for option in optionOrStringLiterals { var regExp: NSRegularExpression? @@ -334,8 +325,7 @@ extension NSMutableAttributedString { AttStr(@"hello").color(@"red").color(@"green") //green color AttStr(@"hello").color(@"red").preventOverride.color(@"green") //red color */ - @discardableResult - public func preventOverride(_ flag: Bool = true) -> Self { + @discardableResult public func preventOverride(_ flag: Bool = true) -> Self { self.cpkPreventOverrideAttribute = flag return self } diff --git a/Cupcake/CPKStackView.swift b/Cupcake/CPKStackView.swift index 4818859..5ed776d 100644 --- a/Cupcake/CPKStackView.swift +++ b/Cupcake/CPKStackView.swift @@ -34,6 +34,7 @@ public class CPKStackView: UIView { private var _alignment: CPKStackAlignment = .left private var _spacing: CGFloat = 0 private var _axis: UILayoutConstraintAxis = .horizontal + private var _headAttachSpace: CGFloat? public private(set) var arrangedSubviews = [UIView]() @@ -98,7 +99,7 @@ public class CPKStackView: UIView { let spacing = CPKFloat(sub) if index == 0 { - self.cpkAttachSpacing = spacing + _headAttachSpace = spacing attachSpaceDidChangeForView(at: -1) } else { let previousView = self.arrangedSubviews[index - 1] @@ -400,6 +401,9 @@ public class CPKStackView: UIView { var spacing: CGFloat = 0 + if item1 == self && _headAttachSpace != nil { + spacing = -_headAttachSpace! + } if let attachSpacing = item1.cpkAttachSpacing { spacing = -attachSpacing } else if item1 != self && item2 != self { @@ -474,6 +478,15 @@ public class CPKStackView: UIView { let item1 = itemAt(index: index) let item2 = itemAt(index: index + 1) + if item1 == self && _headAttachSpace != nil { + for c in self.spacingConstraints { + if c.firstItem === item1 && c.secondItem === item2 { + c.constant = -_headAttachSpace! + break + } + } + } + if let spacing = item1.cpkAttachSpacing { for c in self.spacingConstraints { if c.firstItem === item1 && c.secondItem === item2 { diff --git a/Cupcake/Color.swift b/Cupcake/Color.swift index 3f27bd7..7721812 100644 --- a/Cupcake/Color.swift +++ b/Cupcake/Color.swift @@ -32,7 +32,7 @@ import UIKit Color(Img("image")) //using image ... */ -func Color(_ any: Any?) -> UIColor? { +public func Color(_ any: Any?) -> UIColor? { if any == nil { return nil } diff --git a/Cupcake/StaticTable.swift b/Cupcake/StaticTable.swift index 069bac3..4be0861 100644 --- a/Cupcake/StaticTable.swift +++ b/Cupcake/StaticTable.swift @@ -68,7 +68,7 @@ public extension StaticTableView { .font(someLabel.font) ... */ - @discardableResult func font(_ any: Any) -> Self { + @discardableResult public func font(_ any: Any) -> Self { self.textFont = any return self } @@ -85,7 +85,7 @@ public extension StaticTableView { .color(someLabel.textColor) ... */ - @discardableResult func color(_ any: Any) -> Self { + @discardableResult public func color(_ any: Any) -> Self { self.textColor = any return self } @@ -102,7 +102,7 @@ public extension StaticTableView { .font(someLabel.font) ... */ - @discardableResult func detailFont(_ any: Any) -> Self { + @discardableResult public func detailFont(_ any: Any) -> Self { self.detailFont = any return self } @@ -119,7 +119,7 @@ public extension StaticTableView { .color(someLabel.textColor) ... */ - @discardableResult func detailColor(_ any: Any) -> Self { + @discardableResult public func detailColor(_ any: Any) -> Self { self.detailColor = any return self } @@ -130,7 +130,7 @@ public extension StaticTableView { .rowHeight(50) .rowHeight(-1) //negative value means use UITableViewAutomaticDimension */ - @discardableResult func rowHeight(_ height: CGFloat) -> Self { + @discardableResult public func rowHeight(_ height: CGFloat) -> Self { self.cellHeight = height return self } @@ -141,7 +141,7 @@ public extension StaticTableView { .lineIndent(0) .lineIndent(10) */ - @discardableResult func lineIndent(_ indent: CGFloat) -> Self { + @discardableResult public func lineIndent(_ indent: CGFloat) -> Self { self.separatorIndent = indent return self } @@ -152,7 +152,7 @@ public extension StaticTableView { .arrow() .arrow(false) */ - @discardableResult func arrow(_ showArrow: Bool = true) -> Self { + @discardableResult public func arrow(_ showArrow: Bool = true) -> Self { self.accessoryType = (showArrow ? .disclosureIndicator : nil) return self } @@ -168,7 +168,7 @@ public extension StaticTableView { ... }) */ - @discardableResult func custom(_ handler: @escaping (StaticRow)->()) -> Self { + @discardableResult public func custom(_ handler: @escaping (StaticRow)->()) -> Self { self.customHandler = handler return self } @@ -184,7 +184,7 @@ public extension StaticTableView { ... }) */ - @discardableResult override func onClick(_ callback: @escaping (StaticRow)->()) -> Self { + @discardableResult override public func onClick(_ callback: @escaping (StaticRow)->()) -> Self { self.onClickHandler = callback return self } @@ -202,7 +202,7 @@ public extension StaticSection { .header("Header1") //header with string .header(headerView) //header with view */ - @discardableResult func header(_ any: Any) -> Self { + @discardableResult public func header(_ any: Any) -> Self { self.headerValue = any return self } @@ -216,7 +216,7 @@ public extension StaticSection { .footer("Footer1") //footer with string .footer(footerView) //footer with view */ - @discardableResult func footer(_ any: Any) -> Self { + @discardableResult public func footer(_ any: Any) -> Self { self.footerValue = any return self } @@ -229,7 +229,7 @@ public extension StaticSection { .singleCheck("checked") //use custom image .singleCheck("checked", "unchecked") //use custom images */ - @discardableResult func singleCheck(_ checkedImage: Any? = nil, _ uncheckedImage: Any? = nil) -> Self { + @discardableResult public func singleCheck(_ checkedImage: Any? = nil, _ uncheckedImage: Any? = nil) -> Self { self.enableSingleCheck = true self.checkedImage = checkedImage != nil ? Img(checkedImage!) : nil self.uncheckedImage = uncheckedImage != nil ? Img(uncheckedImage!) : nil @@ -244,7 +244,7 @@ public extension StaticSection { .multiCheck("checked") //use custom image .multiCheck("checked", "unchecked") //use custom images */ - @discardableResult func multiCheck(_ checkedImage: Any? = nil, _ uncheckedImage: Any? = nil) -> Self { + @discardableResult public func multiCheck(_ checkedImage: Any? = nil, _ uncheckedImage: Any? = nil) -> Self { self.enableMultiCheck = true self.checkedImage = checkedImage != nil ? Img(checkedImage!) : nil self.uncheckedImage = uncheckedImage != nil ? Img(uncheckedImage!) : nil @@ -267,7 +267,7 @@ public extension StaticRow { .img(someImage) ... */ - @discardableResult func img(_ any: Any) -> Self { + @discardableResult public func img(_ any: Any) -> Self { self.image = Img(any) return self } @@ -281,7 +281,7 @@ public extension StaticRow { .str( AttStr("hello world").strikethrough() ) ... */ - @discardableResult func str(_ any: Any) -> Self { + @discardableResult public func str(_ any: Any) -> Self { self.text = any return self } @@ -295,7 +295,7 @@ public extension StaticRow { .detail( AttStr("hello world").strikethrough() ) ... */ - @discardableResult func detail(_ any: Any) -> Self { + @discardableResult public func detail(_ any: Any) -> Self { self.detailText = any return self } @@ -307,7 +307,7 @@ public extension StaticRow { .style(.value2) ... */ - @discardableResult func style(_ style: UITableViewCellStyle) -> Self { + @discardableResult public func style(_ style: UITableViewCellStyle) -> Self { self.cellStyle = style return self } @@ -320,7 +320,7 @@ public extension StaticRow { .accessory(.view(someView)) //setting accessoryView ... */ - @discardableResult func accessory(_ type: CPKTableViewCellAccessoryType) -> Self { + @discardableResult public func accessory(_ type: CPKTableViewCellAccessoryType) -> Self { self.accessoryType = type return self } @@ -331,7 +331,7 @@ public extension StaticRow { .arrow() .arrow(false) */ - @discardableResult func arrow(_ showArrow: Bool = true) -> Self { + @discardableResult public func arrow(_ showArrow: Bool = true) -> Self { self.accessoryType = showArrow ? .disclosureIndicator : CPKTableViewCellAccessoryType.none return self } @@ -342,7 +342,7 @@ public extension StaticRow { .check() .check(false) */ - @discardableResult func check(_ checked: Bool = true) -> Self { + @discardableResult public func check(_ checked: Bool = true) -> Self { self.accessoryType = checked ? .checkmark : CPKTableViewCellAccessoryType.none return self } @@ -353,7 +353,7 @@ public extension StaticRow { .switchOn() .switchOn(false) */ - @discardableResult func switchOn(_ isOn: Bool = true) -> Self { + @discardableResult public func switchOn(_ isOn: Bool = true) -> Self { let sw: UISwitch! = self.switchView ?? {self.switchView = UISwitch(); return self.switchView}() sw.isOn = isOn self.accessory(.view(sw)) @@ -366,7 +366,7 @@ public extension StaticRow { .height(50) .height(-1) //negative value means use UITableViewAutomaticDimension */ - @discardableResult func height(_ height: CGFloat) -> Self { + @discardableResult public func height(_ height: CGFloat) -> Self { self.cellHeight = height return self } @@ -376,7 +376,7 @@ public extension StaticRow { * Usages: .lineIndent(10) */ - @discardableResult func lineIndent(_ indent: CGFloat) -> Self { + @discardableResult public func lineIndent(_ indent: CGFloat) -> Self { self.separatorIndent = indent return self } @@ -392,7 +392,7 @@ public extension StaticRow { ... }) */ - @discardableResult override func onClick(_ callback: @escaping (StaticRow)->()) -> Self { + @discardableResult override public func onClick(_ callback: @escaping (StaticRow)->()) -> Self { self.onClickHandler = callback return self } @@ -407,7 +407,7 @@ public extension StaticRow { ... }) */ - @discardableResult func onButton(_ callback: @escaping (StaticRow)->()) -> Self { + @discardableResult public func onButton(_ callback: @escaping (StaticRow)->()) -> Self { self.onButtonHandler = callback return self } @@ -422,7 +422,7 @@ public extension StaticRow { ... }) */ - @discardableResult func onChange(_ callback: @escaping (StaticRow)->()) -> Self { + @discardableResult public func onChange(_ callback: @escaping (StaticRow)->()) -> Self { self.onChangeHandler = callback return self } @@ -437,7 +437,7 @@ public extension StaticRow { ... }) */ - @discardableResult func custom(_ handler: @escaping (StaticRow)->()) -> Self { + @discardableResult public func custom(_ handler: @escaping (StaticRow)->()) -> Self { self.customHandler = handler return self } diff --git a/Cupcake/TextField.swift b/Cupcake/TextField.swift index a73e85d..85b026c 100644 --- a/Cupcake/TextField.swift +++ b/Cupcake/TextField.swift @@ -8,14 +8,14 @@ import UIKit -var TextField: UITextField { +public var TextField: UITextField { let textField = UITextField() textField.enablesReturnKeyAutomatically = true textField.returnKeyType = .done return textField } -extension UITextField { +public extension UITextField { /** * Setting text or attributedText @@ -174,7 +174,7 @@ extension UITextField { .onChange({ _ in /* ... */ }) .onChange({ [weak self] textField in /* ... */ }) //capture self as weak reference when needed */ - @discardableResult func onChange(_ closure: @escaping (UITextField)->()) -> Self { + @discardableResult public func onChange(_ closure: @escaping (UITextField)->()) -> Self { self.cpkTextChangedClosure = cpk_generateCallbackClosure(closure, nil) return self } @@ -188,7 +188,7 @@ extension UITextField { .onFinish({ _ in /* ... */ }) .onFinish({ [weak self] textField in /* ... */ }) //capture self as weak reference when needed */ - @discardableResult func onFinish(_ closure: @escaping (UITextField)->()) -> Self { + @discardableResult public func onFinish(_ closure: @escaping (UITextField)->()) -> Self { self.cpkDidEndOnExistClosure = cpk_generateCallbackClosure(closure, nil) return self } diff --git a/Cupcake/TextView.swift b/Cupcake/TextView.swift index a9075ae..80e93f2 100644 --- a/Cupcake/TextView.swift +++ b/Cupcake/TextView.swift @@ -8,11 +8,11 @@ import UIKit -var TextView: UITextView { +public var TextView: UITextView { return UITextView().font(17) } -extension UITextView { +public extension UITextView { /** * Setting text or attributedText @@ -120,7 +120,7 @@ extension UITextView { .onChange({ _ in /* ... */ }) .onChange({ [weak self] textView in /* ... */ }) //capture self as weak reference when needed */ - @discardableResult func onChange(_ closure: @escaping (UITextView)->()) -> Self { + @discardableResult public func onChange(_ closure: @escaping (UITextView)->()) -> Self { self.cpkTextChangedClosure = cpk_generateCallbackClosure(closure, nil) return self } diff --git a/Cupcake/View.swift b/Cupcake/View.swift index f3260f0..112fcb9 100644 --- a/Cupcake/View.swift +++ b/Cupcake/View.swift @@ -13,7 +13,7 @@ public var View: UIView { return view } -extension UIView { +public extension UIView { /** * Setting background with Color or Image. @@ -151,7 +151,7 @@ extension UIView { .onClick({ _ in /* ... */ }) //if you don't care at all .onClick({ [weak self] _ in /* ... */ }) //capture self as weak reference when needed */ - @discardableResult func onClick(_ closure: @escaping (UIView)->()) -> Self { + @discardableResult public func onClick(_ closure: @escaping (UIView)->()) -> Self { cpk_onClick(closure, nil) return self } @@ -296,10 +296,9 @@ public extension UIView { .embedIn(superview, 10, 20, 30, 40) //top: 10, left: 20, bottom: 30, right: 40 .embedIn(superview, 10, 20, nil) //top: 10, left: 20 */ - @discardableResult - public func embedIn(_ superview: UIView, - _ p1: Any? = "", _ p2: Any? = "", - _ p3: Any? = "", _ p4: Any? = "") -> Self { + @discardableResult public func embedIn(_ superview: UIView, + _ p1: Any? = "", _ p2: Any? = "", + _ p3: Any? = "", _ p4: Any? = "") -> Self { superview.addSubview(self) let edge = cpk_edgeInsetsTupleFromParameters(p1, p2, p3, p4) diff --git a/Cupcake/__Private__Implementations__.swift b/Cupcake/__Private__Implementations__.swift index e32bcbb..598caa7 100644 --- a/Cupcake/__Private__Implementations__.swift +++ b/Cupcake/__Private__Implementations__.swift @@ -2741,7 +2741,7 @@ extension UILabel { } @discardableResult - override func onClick(_ closure: @escaping (UILabel)->()) -> Self { + override public func onClick(_ closure: @escaping (UILabel)->()) -> Self { cpk_onClick(closure, nil) return self } @@ -2830,7 +2830,7 @@ extension UIImageView { } @discardableResult - override func onClick(_ closure: @escaping (UIImageView)->()) -> Self { + override public func onClick(_ closure: @escaping (UIImageView)->()) -> Self { cpk_onClick(closure, nil) return self } @@ -2913,7 +2913,7 @@ extension UIButton { } @discardableResult - override func onClick(_ closure: @escaping (UIButton)->()) -> Self { + override public func onClick(_ closure: @escaping (UIButton)->()) -> Self { cpk_onClick(closure, nil) return self } @@ -3002,7 +3002,7 @@ extension UITextField { } @discardableResult - override func onClick(_ closure: @escaping (UITextField)->()) -> Self { + override public func onClick(_ closure: @escaping (UITextField)->()) -> Self { cpk_onClick(closure, nil) return self } @@ -3091,7 +3091,7 @@ extension UITextView { } @discardableResult - override func onClick(_ closure: @escaping (UITextView)->()) -> Self { + override public func onClick(_ closure: @escaping (UITextView)->()) -> Self { cpk_onClick(closure, nil) return self } @@ -3180,7 +3180,7 @@ extension CPKStackView { } @discardableResult - override func onClick(_ closure: @escaping (CPKStackView)->()) -> Self { + override public func onClick(_ closure: @escaping (CPKStackView)->()) -> Self { cpk_onClick(closure, nil) return self }