-
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.
[Add, Feat] #6 - (UIButton+Extension) Configure 함수 생성
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 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
59 changes: 59 additions & 0 deletions
59
35-seminar/Presentation/Week2/Extensions/UIButton+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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// UIButton+Extension.swift | ||
// 35-seminar | ||
// | ||
// Created by 김유림 on 10/24/24. | ||
// | ||
|
||
import UIKit | ||
|
||
enum ConfigurationType { | ||
case plain | ||
case filled | ||
} | ||
|
||
extension UIButton { | ||
func configureButton(configType: ConfigurationType = .plain, | ||
title: String? = nil, | ||
fontSize: CGFloat = 17, | ||
fontWeight: UIFont.Weight = .regular, | ||
image: UIImage? = nil, | ||
symbolWeight: UIImage.SymbolWeight = .unspecified, | ||
cornerStyle: UIButton.Configuration.CornerStyle? = nil, | ||
foregroundColor: UIColor = .tintColor, | ||
backgroundColor: UIColor = .clear, | ||
for state: UIControl.State = .normal) { | ||
|
||
var config = { | ||
switch configType { | ||
case .plain: | ||
return UIButton.Configuration.plain() | ||
case .filled: | ||
return UIButton.Configuration.filled() | ||
} | ||
}() | ||
|
||
print(config) | ||
|
||
if let title = title { | ||
let attributes: [NSAttributedString.Key: Any] = [.font : UIFont.systemFont(ofSize: fontSize, weight: fontWeight)] | ||
let attributedTitle = NSAttributedString(string: title, attributes: attributes) | ||
self.setAttributedTitle(attributedTitle, for: state) | ||
} | ||
|
||
if let image = image { | ||
let symbolConfig = UIImage.SymbolConfiguration(weight: symbolWeight) | ||
image.withConfiguration(symbolConfig) | ||
config.image = image | ||
} | ||
|
||
if let cornerStyle = cornerStyle { | ||
config.cornerStyle = cornerStyle | ||
} | ||
|
||
config.baseForegroundColor = foregroundColor | ||
config.baseBackgroundColor = backgroundColor | ||
|
||
self.configuration = config | ||
} | ||
} |