-
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
1 changed file
with
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// ZatchButton.swift | ||
// Zatch | ||
// | ||
// Created by 박소윤 on 2023/02/11. | ||
// | ||
|
||
import Foundation | ||
|
||
extension ZatchComponent{ | ||
|
||
enum ZatchButtonConfiguration{ | ||
case height48 | ||
} | ||
|
||
class ZatchButton: UIButton{ | ||
|
||
var offset: CGFloat{ | ||
config.offset | ||
} | ||
|
||
private let config: ZatchButtonConfiguration | ||
|
||
init(title: String, configuration: ZatchButtonConfiguration){ | ||
self.config = configuration | ||
super.init(frame: .zero) | ||
self.setTitle(title, for: .normal) | ||
initialize() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
private func initialize(){ | ||
style() | ||
layout() | ||
} | ||
|
||
private func style(){ | ||
self.layer.cornerRadius = config.height / 2 | ||
self.titleLabel?.setTypoStyleWithSingleLine(typoStyle: config.typo) | ||
} | ||
|
||
private func layout(){ | ||
self.snp.makeConstraints{ | ||
$0.height.equalTo(config.height) | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
extension ZatchComponent.ZatchButtonConfiguration{ | ||
|
||
var height: CGFloat{ | ||
switch self{ | ||
case .height48: return 48 | ||
} | ||
} | ||
|
||
var typo: TypoStyle{ | ||
switch self{ | ||
case .height48: return .bold18 | ||
} | ||
} | ||
|
||
var offset: CGFloat{ | ||
switch self{ | ||
case .height48: return 56 | ||
} | ||
} | ||
} |