Skip to content

Commit

Permalink
[Add, Feat] #6 - (UIButton+Extension) Configure 함수 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
yurim830 committed Oct 24, 2024
1 parent e5b04f7 commit 38591f7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
4 changes: 4 additions & 0 deletions 35-seminar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
1590A6A12CBE737600FB32AE /* PractScrollViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1590A6A02CBE737600FB32AE /* PractScrollViewController.swift */; };
1590A6A42CBE8A9200FB32AE /* AppDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1590A6A32CBE8A9200FB32AE /* AppDetailViewController.swift */; };
1590A6A62CBE8AA600FB32AE /* AppDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1590A6A52CBE8AA600FB32AE /* AppDetailView.swift */; };
15EC30532CCA434700A0480B /* UIButton+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15EC30522CCA434700A0480B /* UIButton+Extension.swift */; };
15F4FD072CC73D0A00C99A20 /* StarStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F4FD062CC73D0A00C99A20 /* StarStackView.swift */; };
15F4FD0F2CC7649A00C99A20 /* BorderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F4FD0E2CC7649A00C99A20 /* BorderView.swift */; };
/* End PBXBuildFile section */
Expand All @@ -47,6 +48,7 @@
1590A6A02CBE737600FB32AE /* PractScrollViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PractScrollViewController.swift; sourceTree = "<group>"; };
1590A6A32CBE8A9200FB32AE /* AppDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDetailViewController.swift; sourceTree = "<group>"; };
1590A6A52CBE8AA600FB32AE /* AppDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDetailView.swift; sourceTree = "<group>"; };
15EC30522CCA434700A0480B /* UIButton+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIButton+Extension.swift"; sourceTree = "<group>"; };
15F4FD062CC73D0A00C99A20 /* StarStackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StarStackView.swift; sourceTree = "<group>"; };
15F4FD0E2CC7649A00C99A20 /* BorderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BorderView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -96,6 +98,7 @@
isa = PBXGroup;
children = (
157119DC2CBE96F500362252 /* UILabel+Extension.swift */,
15EC30522CCA434700A0480B /* UIButton+Extension.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -276,6 +279,7 @@
1590A6402CBE6C6A00FB32AE /* AppDelegate.swift in Sources */,
1590A6412CBE6C6A00FB32AE /* SceneDelegate.swift in Sources */,
157119D62CBE962F00362252 /* TitleLabel.swift in Sources */,
15EC30532CCA434700A0480B /* UIButton+Extension.swift in Sources */,
1590A6A42CBE8A9200FB32AE /* AppDetailViewController.swift in Sources */,
1590A6A62CBE8AA600FB32AE /* AppDetailView.swift in Sources */,
1590A6422CBE6C6A00FB32AE /* Week1DetailView.swift in Sources */,
Expand Down
59 changes: 59 additions & 0 deletions 35-seminar/Presentation/Week2/Extensions/UIButton+Extension.swift
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
}
}

0 comments on commit 38591f7

Please sign in to comment.