diff --git a/CheoMooRac/CheoMooRac/Sources/Exensions/UIButton+setBackgroundColor.swift b/CheoMooRac/CheoMooRac/Sources/Exensions/UIButton+setBackgroundColor.swift new file mode 100644 index 0000000..db7c043 --- /dev/null +++ b/CheoMooRac/CheoMooRac/Sources/Exensions/UIButton+setBackgroundColor.swift @@ -0,0 +1,22 @@ +// +// UIButton+setBackgroundColor.swift +// CheoMooRac +// +// Created by 김윤서 on 2021/09/15. +// + +import UIKit + +extension UIButton { + func setBackgroundColor(_ color: UIColor, for state: UIControl.State) { + UIGraphicsBeginImageContext(CGSize(width: 1.0, height: 1.0)) + guard let context = UIGraphicsGetCurrentContext() else { return } + context.setFillColor(color.cgColor) + context.fill(CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0)) + + let backgroundImage = UIGraphicsGetImageFromCurrentImageContext() + UIGraphicsEndImageContext() + + setBackgroundImage(backgroundImage, for: state) + } +} diff --git a/CheoMooRac/CheoMooRac/Sources/Exensions/UIStackView+addArrangedSubviews.swift b/CheoMooRac/CheoMooRac/Sources/Exensions/UIStackView+addArrangedSubviews.swift new file mode 100644 index 0000000..e89e35c --- /dev/null +++ b/CheoMooRac/CheoMooRac/Sources/Exensions/UIStackView+addArrangedSubviews.swift @@ -0,0 +1,14 @@ +// +// UIStackView+addArrangedSubviews.swift +// CheoMooRac +// +// Created by 김윤서 on 2021/09/14. +// + +import UIKit + +extension UIStackView { + func addArrangedSubviews(_ views: UIView...) { + for view in views { addArrangedSubview(view) } + } +} diff --git a/CheoMooRac/CheoMooRac/Sources/Exensions/UITableView+Generic.swift b/CheoMooRac/CheoMooRac/Sources/Exensions/UITableView+Generic.swift new file mode 100644 index 0000000..801a5bc --- /dev/null +++ b/CheoMooRac/CheoMooRac/Sources/Exensions/UITableView+Generic.swift @@ -0,0 +1,44 @@ +// +// UITableView+Generic.swift +// CheoMooRac +// +// Created by 김윤서 on 2021/09/14. +// + +import UIKit + +protocol Reusable: AnyObject { + static var reuseIdentifier: String { get } + static var nib: UINib? { get } +} + +extension Reusable { + static var reuseIdentifier: String { return String(describing: self) } + static var nib: UINib? { return nil } +} + +extension UITableView { + func registerReusableCell(_: T.Type) where T: Reusable { + if let nib = T.nib { + self.register(nib, forCellReuseIdentifier: T.reuseIdentifier) + } else { + self.register(T.self, forCellReuseIdentifier: T.reuseIdentifier) + } + } + + func dequeueReusableCell(indexPath: IndexPath) -> T where T: Reusable { + return self.dequeueReusableCell(withIdentifier: T.reuseIdentifier, for: indexPath as IndexPath) as! T + } + + func registerReusableHeaderFooterView(_: T.Type) where T: Reusable { + if let nib = T.nib { + self.register(nib, forHeaderFooterViewReuseIdentifier: T.reuseIdentifier) + } else { + self.register(T.self, forHeaderFooterViewReuseIdentifier: T.reuseIdentifier) + } + } + + func dequeueReusableHeaderFooterView() -> T where T: Reusable { + return self.dequeueReusableHeaderFooterView(withIdentifier: T.reuseIdentifier) as! T + } +} diff --git a/CheoMooRac/CheoMooRac/Sources/Exensions/UIView+addSubviews.swift b/CheoMooRac/CheoMooRac/Sources/Exensions/UIView+addSubviews.swift new file mode 100644 index 0000000..c9ce3fe --- /dev/null +++ b/CheoMooRac/CheoMooRac/Sources/Exensions/UIView+addSubviews.swift @@ -0,0 +1,14 @@ +// +// UIView+addSubviews.swift +// CheoMooRac +// +// Created by 김윤서 on 2021/09/14. +// + +import UIKit + +extension UIView { + func addSubviews(_ views: UIView...) { + for view in views { addSubview(view) } + } +}