-
Notifications
You must be signed in to change notification settings - Fork 0
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
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
CheoMooRac/CheoMooRac/Sources/Exensions/UIButton+setBackgroundColor.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,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) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
CheoMooRac/CheoMooRac/Sources/Exensions/UIStackView+addArrangedSubviews.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,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) } | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
CheoMooRac/CheoMooRac/Sources/Exensions/UITableView+Generic.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,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: UITableViewCell>(_: 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<T: UITableViewCell>(indexPath: IndexPath) -> T where T: Reusable { | ||
return self.dequeueReusableCell(withIdentifier: T.reuseIdentifier, for: indexPath as IndexPath) as! T | ||
} | ||
|
||
func registerReusableHeaderFooterView<T: UITableViewHeaderFooterView>(_: 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: UITableViewHeaderFooterView>() -> T where T: Reusable { | ||
return self.dequeueReusableHeaderFooterView(withIdentifier: T.reuseIdentifier) as! T | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
CheoMooRac/CheoMooRac/Sources/Exensions/UIView+addSubviews.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,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) } | ||
} | ||
} |