-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
342 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import UIKit | ||
|
||
extension UIColor { | ||
public func fillImage(_ size: CGSize = .init(width: 1, height: 1), cornerRadius: CGFloat = 0.0) -> UIImage { | ||
return UIGraphicsImageRenderer(size: size) | ||
.image { _ in | ||
self.setFill() | ||
let bezierPath = UIBezierPath(roundedRect: CGRect(origin: .zero, size: size), cornerRadius: cornerRadius) | ||
bezierPath.fill() | ||
} | ||
} | ||
|
||
public func fillCircleImage(_ size: CGSize = .init(width: 1, height: 1)) -> UIImage { | ||
let cornerRadius = min(size.width, size.height) / 2.0 | ||
return fillImage(size, cornerRadius: cornerRadius) | ||
} | ||
|
||
public func fillImage(_ size: CGSize = .init(width: 1, height: 1)) -> UIImage { | ||
return UIGraphicsImageRenderer(size: size) | ||
.image { _ in | ||
self.setFill() | ||
let bezierPath = UIBezierPath(rect: CGRect(origin: .zero, size: size)) | ||
bezierPath.fill() | ||
} | ||
} | ||
|
||
public func strokeCircleImage(_ size: CGSize, lineWidth: CGFloat = 2) -> UIImage { | ||
let cornerRadius = min(size.width, size.height) / 2.0 | ||
return strokeImage(size, cornerRadius: cornerRadius, lineWidth: lineWidth) | ||
} | ||
|
||
public func strokeImage(_ size: CGSize, cornerRadius: CGFloat = 0.0, lineWidth: CGFloat = 2) -> UIImage { | ||
return UIGraphicsImageRenderer(size: size) | ||
.image { _ in | ||
self.setStroke() | ||
let bezierPath = UIBezierPath(roundedRect: CGRect(origin: .zero, size: size).insetBy(dx: lineWidth, dy: lineWidth), cornerRadius: cornerRadius) | ||
bezierPath.lineWidth = lineWidth | ||
bezierPath.stroke() | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import UIKit | ||
|
||
extension UIControl { | ||
func add (events: UIControl.Event, for handler: @escaping () -> Void) { | ||
let handler = HandlerWrapper(handler) | ||
addTarget(handler, action: #selector(HandlerWrapper.invoke), for: events) | ||
objc_setAssociatedObject(self, String(ObjectIdentifier(self).hashValue) + String(events.rawValue), handler, .OBJC_ASSOCIATION_RETAIN) | ||
} | ||
} | ||
|
||
class HandlerWrapper { | ||
let handler: () -> Void | ||
|
||
init (_ handler: @escaping () -> Void) { | ||
self.handler = handler | ||
} | ||
|
||
@objc func invoke () { | ||
handler() | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
Sources/UIKitAdditions/Extensions/UIEdgeInsets+Extension.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import UIKit | ||
|
||
extension UIEdgeInsets { | ||
public init(bottom: CGFloat = 0.0, right: CGFloat = 0.0, top: CGFloat = 0.0, left: CGFloat = 0.0) { | ||
self.init(top: top, left: left, bottom: bottom, right: right) | ||
public init(size: CGFloat) { | ||
self.init(top: size, left: size, bottom: size, right: size) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
140 changes: 70 additions & 70 deletions
140
Sources/UIKitAdditions/Extensions/UINavigationController+Extension.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,72 @@ | ||
import UIKit | ||
|
||
extension UINavigationController { | ||
@discardableResult | ||
func popToViewController(type: UIViewController.Type, animated: Bool) -> [UIViewController]? { | ||
guard | ||
let foundViewController = self.viewControllers.filter({ $0.identifier == type.identifier }).first | ||
else { return nil } | ||
return popToViewController(foundViewController, animated: true) | ||
} | ||
} | ||
|
||
extension UINavigationController { | ||
open override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { | ||
return self.viewControllers.first?.preferredInterfaceOrientationForPresentation ?? super.preferredInterfaceOrientationForPresentation | ||
} | ||
|
||
open override var transitioningDelegate: UIViewControllerTransitioningDelegate? { | ||
get { | ||
return self.viewControllers.first?.transitioningDelegate ?? super.transitioningDelegate | ||
} | ||
|
||
set { | ||
|
||
if let rootViewController = self.viewControllers.first { | ||
rootViewController.transitioningDelegate = newValue | ||
} else { | ||
super.transitioningDelegate = newValue | ||
} | ||
} | ||
} | ||
|
||
open override var preferredStatusBarStyle: UIStatusBarStyle { | ||
return self.viewControllers.first?.preferredStatusBarStyle ?? super.preferredStatusBarStyle | ||
} | ||
|
||
open override var prefersStatusBarHidden: Bool { | ||
return self.viewControllers.first?.prefersStatusBarHidden ?? super.prefersStatusBarHidden | ||
} | ||
|
||
open override var modalPresentationStyle: UIModalPresentationStyle { | ||
get { | ||
return self.viewControllers.first?.modalPresentationStyle ?? super.modalPresentationStyle | ||
} | ||
|
||
set { | ||
if let rootViewController = self.viewControllers.first { | ||
rootViewController.modalPresentationStyle = newValue | ||
} else { | ||
super.modalPresentationStyle = newValue | ||
} | ||
} | ||
} | ||
|
||
open override var modalTransitionStyle: UIModalTransitionStyle { | ||
get { | ||
return self.viewControllers.first?.modalTransitionStyle ?? super.modalTransitionStyle | ||
} | ||
|
||
set { | ||
if let rootViewController = self.viewControllers.first { | ||
rootViewController.modalTransitionStyle = newValue | ||
} else { | ||
super.modalTransitionStyle = newValue | ||
} | ||
} | ||
} | ||
|
||
open override var shouldAutorotate: Bool { | ||
return self.topViewController?.shouldAutorotate ?? super.shouldAutorotate | ||
} | ||
} | ||
//extension UINavigationController { | ||
// @discardableResult | ||
// func popToViewController(type: UIViewController.Type, animated: Bool) -> [UIViewController]? { | ||
// guard | ||
// let foundViewController = self.viewControllers.filter({ $0.identifier == type.identifier }).first | ||
// else { return nil } | ||
// return popToViewController(foundViewController, animated: true) | ||
// } | ||
//} | ||
// | ||
//extension UINavigationController { | ||
// open override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { | ||
// return self.viewControllers.first?.preferredInterfaceOrientationForPresentation ?? super.preferredInterfaceOrientationForPresentation | ||
// } | ||
// | ||
// open override var transitioningDelegate: UIViewControllerTransitioningDelegate? { | ||
// get { | ||
// return self.viewControllers.first?.transitioningDelegate ?? super.transitioningDelegate | ||
// } | ||
// | ||
// set { | ||
// | ||
// if let rootViewController = self.viewControllers.first { | ||
// rootViewController.transitioningDelegate = newValue | ||
// } else { | ||
// super.transitioningDelegate = newValue | ||
// } | ||
// } | ||
// } | ||
// | ||
// open override var preferredStatusBarStyle: UIStatusBarStyle { | ||
// return self.viewControllers.first?.preferredStatusBarStyle ?? super.preferredStatusBarStyle | ||
// } | ||
// | ||
// open override var prefersStatusBarHidden: Bool { | ||
// return self.viewControllers.first?.prefersStatusBarHidden ?? super.prefersStatusBarHidden | ||
// } | ||
// | ||
// open override var modalPresentationStyle: UIModalPresentationStyle { | ||
// get { | ||
// return self.viewControllers.first?.modalPresentationStyle ?? super.modalPresentationStyle | ||
// } | ||
// | ||
// set { | ||
// if let rootViewController = self.viewControllers.first { | ||
// rootViewController.modalPresentationStyle = newValue | ||
// } else { | ||
// super.modalPresentationStyle = newValue | ||
// } | ||
// } | ||
// } | ||
// | ||
// open override var modalTransitionStyle: UIModalTransitionStyle { | ||
// get { | ||
// return self.viewControllers.first?.modalTransitionStyle ?? super.modalTransitionStyle | ||
// } | ||
// | ||
// set { | ||
// if let rootViewController = self.viewControllers.first { | ||
// rootViewController.modalTransitionStyle = newValue | ||
// } else { | ||
// super.modalTransitionStyle = newValue | ||
// } | ||
// } | ||
// } | ||
// | ||
// open override var shouldAutorotate: Bool { | ||
// return self.topViewController?.shouldAutorotate ?? super.shouldAutorotate | ||
// } | ||
//} |
18 changes: 18 additions & 0 deletions
18
Sources/UIKitAdditions/Extensions/UIStackView+Extensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import UIKit | ||
|
||
extension UIStackView { | ||
public func addArrangedSubviews(_ views: [UIView]) { | ||
views.forEach { addArrangedSubview($0) } | ||
} | ||
|
||
@discardableResult | ||
public func removeAllArrangedSubviews() -> [UIView] { | ||
let removedSubviews = arrangedSubviews.reduce([]) { (removedSubviews, subview) -> [UIView] in | ||
self.removeArrangedSubview(subview) | ||
NSLayoutConstraint.deactivate(subview.constraints) | ||
subview.removeFromSuperview() | ||
return removedSubviews + [subview] | ||
} | ||
return removedSubviews | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.