diff --git a/Sources/CALayer+Theme.swift b/Sources/CALayer+Theme.swift new file mode 100644 index 0000000..91c88a1 --- /dev/null +++ b/Sources/CALayer+Theme.swift @@ -0,0 +1,21 @@ +// +// CALayer+Theme.swift +// +// +// Created by Hooi Ling on 14/12/22. +// + +import Foundation +import QuartzCore + +extension CALayer { + /// Sets corner radius on CALayer + /// + /// Triggered by SwiftTheme when theme_cornerRadius is used. + /// - Parameter value: a `ThemeCGFloatPicker` value + /// + /// Not called setCornerRadius so as not to conflict with existing func with same name. + @objc func customSetCornerRadius(_ value: CGFloat) { + cornerRadius = value + } +} diff --git a/Sources/NSLayoutConstraint+Theme.swift b/Sources/NSLayoutConstraint+Theme.swift new file mode 100644 index 0000000..8d1d862 --- /dev/null +++ b/Sources/NSLayoutConstraint+Theme.swift @@ -0,0 +1,21 @@ +// +// NSLayoutConstraint+Theme.swift +// +// Setters used by ThemePickers operating on NSLayoutConstraint. +// +// Created by Ryan Tan on 29/11/22. +// + +import UIKit + +#if os(iOS) +extension NSLayoutConstraint { + + /// Sets constant for the constraint. + /// + /// Triggered by SwiftTheme when theme_constraintConstant is used. + @objc func setConstraintConstant(_ value: CGFloat) { + constant = value + } +} +#endif diff --git a/Sources/UIKit+Theme.swift b/Sources/UIKit+Theme.swift index 5d33d41..1c4114b 100644 --- a/Sources/UIKit+Theme.swift +++ b/Sources/UIKit+Theme.swift @@ -22,6 +22,18 @@ import UIKit get { return getThemePicker(self, "setTintColor:") as? ThemeColorPicker } set { setThemePicker(self, "setTintColor:", newValue) } } + var theme_backgroundColorOrGradient: ThemeAnyPicker? { + get { return getThemePicker(self, "setBackgroundColorOrGradient:") as? ThemeAnyPicker } + set { setThemePicker(self, "setBackgroundColorOrGradient:", newValue) } + } + var theme_widthConstant: ThemeCGFloatPicker? { + get { return getThemePicker(self, "setWidthConstantConstraint:") as? ThemeCGFloatPicker } + set { setThemePicker(self, "setWidthConstantConstraint:", newValue) } + } + var theme_heightConstant: ThemeCGFloatPicker? { + get { return getThemePicker(self, "setHeightConstantConstraint:") as? ThemeCGFloatPicker } + set { setThemePicker(self, "setHeightConstantConstraint:", newValue) } + } } @objc public extension UIApplication { @@ -152,6 +164,16 @@ import UIKit get { return getThemePicker(self, "setSelectedImage:") as? ThemeImagePicker } set { setThemePicker(self, "setSelectedImage:", newValue) } } + + var theme_titlePositionAdjustmentVertical: ThemeCGFloatPicker? { + get { return getThemePicker(self, "setTitlePositionAdjustmentVertical:") as? ThemeCGFloatPicker } + set { setThemePicker(self, "setTitlePositionAdjustmentVertical:", newValue) } + } + + var theme_titlePositionAdjustmentVerticalNegative: ThemeCGFloatPicker? { + get { return getThemePicker(self, "setTitlePositionAdjustmentVerticalNegative:") as? ThemeCGFloatPicker } + set { setThemePicker(self, "setTitlePositionAdjustmentVerticalNegative:", newValue) } + } } @objc public extension UITableView { @@ -311,6 +333,14 @@ import UIKit get { return getThemePicker(self, "setFillColor:") as? ThemeCGColorPicker } set { setThemePicker(self, "setFillColor:", newValue) } } + var theme_figmaShadow: ThemeAnyPicker? { + get { return getThemePicker(self, "setFigmaShadowTokens:") as? ThemeAnyPicker } + set { setThemePicker(self, "setFigmaShadowTokens:", newValue) } + } + var theme_cornerRadius: ThemeCGFloatPicker? { + get { return getThemePicker(self, "customSetCornerRadius:") as? ThemeCGFloatPicker } + set { setThemePicker(self, "customSetCornerRadius:", newValue) } + } } @objc public extension CATextLayer { @@ -397,6 +427,59 @@ import UIKit set { setThemePicker(self, "setEffect:", newValue) } } } +@objc public extension NSLayoutConstraint +{ + var theme_constraintConstant: ThemeCGFloatPicker? { + get { return getThemePicker(self, "setConstraintConstant:") as? ThemeCGFloatPicker } + set { setThemePicker(self, "setConstraintConstant:", newValue) } + } +} + +@available(iOS 13.0, *) +@objc public extension NSCollectionLayoutSection +{ + var theme_sectionInterGroupSpacing: ThemeCGFloatPicker? { + get { return getThemePicker(self, "setSectionInterGroupSpacing:") as? ThemeCGFloatPicker } + set { setThemePicker(self, "setSectionInterGroupSpacing:", newValue) } + } +} + + +@objc public extension UIStackView +{ + var theme_stackViewSpacing: ThemeCGFloatPicker? { + get { return getThemePicker(self, "setStackViewSpacing:") as? ThemeCGFloatPicker } + set { setThemePicker(self, "setStackViewSpacing:", newValue) } + } + var theme_paddingLeft: ThemeCGFloatPicker? { + get { return getThemePicker(self, "setStackViewPaddingLeft:") as? ThemeCGFloatPicker } + set { setThemePicker(self, "setStackViewPaddingLeft:", newValue) } + } + var theme_paddingTop: ThemeCGFloatPicker? { + get { return getThemePicker(self, "setStackViewPaddingTop:") as? ThemeCGFloatPicker } + set { setThemePicker(self, "setStackViewPaddingTop:", newValue) } + } + var theme_paddingRight: ThemeCGFloatPicker? { + get { return getThemePicker(self, "setStackViewPaddingRight:") as? ThemeCGFloatPicker } + set { setThemePicker(self, "setStackViewPaddingRight:", newValue) } + } + var theme_paddingBottom: ThemeCGFloatPicker? { + get { return getThemePicker(self, "setStackViewPaddingBottom:") as? ThemeCGFloatPicker } + set { setThemePicker(self, "setStackViewPaddingBottom:", newValue) } + } + var theme_paddingVertical: ThemeCGFloatPicker? { + get { return getThemePicker(self, "setStackViewPaddingVertical:") as? ThemeCGFloatPicker } + set { setThemePicker(self, "setStackViewPaddingVertical:", newValue) } + } + var theme_paddingHorizontal: ThemeCGFloatPicker? { + get { return getThemePicker(self, "setStackViewPaddingHorizontal:") as? ThemeCGFloatPicker } + set { setThemePicker(self, "setStackViewPaddingHorizontal:", newValue) } + } + var theme_padding: ThemeCGFloatPicker? { + get { return getThemePicker(self, "setStackViewPadding:") as? ThemeCGFloatPicker } + set { setThemePicker(self, "setStackViewPadding:", newValue) } + } +} @available(iOS 13.0, *) @objc public extension UINavigationBarAppearance { diff --git a/Sources/UIStackview+Theme.swift b/Sources/UIStackview+Theme.swift new file mode 100644 index 0000000..3749289 --- /dev/null +++ b/Sources/UIStackview+Theme.swift @@ -0,0 +1,86 @@ +// +// UIStackview+Theme.swift +// +// Setters used by ThemePickers operating on UIStackView. +// +// Created by Ryan Tan on 29/11/22. +// + +import UIKit + +#if os(iOS) +extension UIStackView { + + /// Sets spacing on stack views.. + /// + /// Triggered by SwiftTheme when theme_stackViewSpacing is used. + @objc func setStackViewSpacing(_ value: CGFloat) { + spacing = value + } + + /// Sets padding left on stack views. + /// + /// Triggered by SwiftTheme when theme_paddingLeft is used. + /// - Parameter value: a `ThemeCGFloatPicker` value + @objc func setStackViewPaddingLeft(_ value: CGFloat) { + isLayoutMarginsRelativeArrangement = true + layoutMargins.left = value + } + + /// Sets padding top on stack views. + /// + /// Triggered by SwiftTheme when theme_paddingTop is used. + /// - Parameter value: a `ThemeCGFloatPicker` value + @objc func setStackViewPaddingTop(_ value: CGFloat) { + isLayoutMarginsRelativeArrangement = true + layoutMargins.top = value + } + + /// Sets padding right on stack views. + /// + /// Triggered by SwiftTheme when theme_paddingRight is used. + /// - Parameter value: a `ThemeCGFloatPicker` value + @objc func setStackViewPaddingRight(_ value: CGFloat) { + isLayoutMarginsRelativeArrangement = true + layoutMargins.right = value + } + + /// Sets padding bottom on stack views. + /// + /// Triggered by SwiftTheme when theme_paddingBottom is used. + /// - Parameter value: a `ThemeCGFloatPicker` value + @objc func setStackViewPaddingBottom(_ value: CGFloat) { + isLayoutMarginsRelativeArrangement = true + layoutMargins.bottom = value + } + + /// Sets padding for vertical (top, bottom) on stack views. + /// + /// Triggered by SwiftTheme when theme_paddingVertical is used. + /// - Parameter value: a `ThemeCGFloatPicker` value + @objc func setStackViewPaddingVertical(_ value: CGFloat) { + isLayoutMarginsRelativeArrangement = true + layoutMargins.top = value + layoutMargins.bottom = value + } + + /// Sets padding for horizontal (leading, trailing) on stack views. + /// + /// Triggered by SwiftTheme when theme_paddingHorizontal is used. + /// - Parameter value: a `ThemeCGFloatPicker` value + @objc func setStackViewPaddingHorizontal(_ value: CGFloat) { + isLayoutMarginsRelativeArrangement = true + layoutMargins.left = value + layoutMargins.right = value + } + + /// Sets padding all sides on stack views. + /// + /// Triggered by SwiftTheme when theme_padding is used. + /// - Parameter value: a `ThemeCGFloatPicker` value + @objc func setStackViewPadding(_ value: CGFloat) { + isLayoutMarginsRelativeArrangement = true + layoutMargins = UIEdgeInsets(top: value, left: value, bottom: value, right: value) + } +} +#endif diff --git a/Sources/UITabBarItem+Theme.swift b/Sources/UITabBarItem+Theme.swift new file mode 100644 index 0000000..20a704c --- /dev/null +++ b/Sources/UITabBarItem+Theme.swift @@ -0,0 +1,28 @@ +// +// File.swift +// +// +// Created by Hooi Ling on 13/12/22. +// + + +import UIKit + +#if os(iOS) +extension UITabBarItem { + + /// Sets vertical value for titlePositionAdjustment. + /// + /// Triggered by SwiftTheme when `theme_titlePositionAdjustmentVertical` is used. + @objc func setTitlePositionAdjustmentVertical(_ value: CGFloat) { + titlePositionAdjustment = UIOffset(horizontal: 0, vertical: value) + } + + /// Sets negative vertical value for titlePositionAdjustment. + /// + /// Triggered by SwiftTheme when `theme_titlePositionAdjustmentVerticalNegative` is used. + @objc func setTitlePositionAdjustmentVerticalNegative(_ value: CGFloat) { + titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -value) + } +} +#endif