-
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
9 changed files
with
275 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,26 @@ | ||
// | ||
// NSAttributedString+.swift | ||
// KkuMulKum | ||
// | ||
// Created by 김진웅 on 6/30/24. | ||
// | ||
|
||
import UIKit | ||
|
||
extension NSAttributedString { | ||
static func pretendardString( | ||
_ text: String = "", | ||
style: UIFont.Pretendard | ||
) -> NSAttributedString { | ||
let paragraphStyle = NSMutableParagraphStyle() | ||
paragraphStyle.paragraphSpacing = style.leading | ||
|
||
let attributes: [NSAttributedString.Key: Any] = [ | ||
.paragraphStyle: paragraphStyle, | ||
.font: UIFont.pretendard(style), | ||
.kern: style.tracking | ||
] | ||
|
||
return NSAttributedString(string: text, attributes: attributes) | ||
} | ||
} |
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,31 @@ | ||
// | ||
// UIButton+.swift | ||
// KkuMulKum | ||
// | ||
// Created by 김진웅 on 6/30/24. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIButton { | ||
func setTitle(_ title: String, style: UIFont.Pretendard, color: UIColor) { | ||
setAttributedTitle(.pretendardString(title, style: style), for: .normal) | ||
setTitleColor(color, for: .normal) | ||
} | ||
|
||
func setLayer(borderWidth: CGFloat = 0, borderColor: UIColor, cornerRadius: CGFloat) { | ||
layer.borderColor = borderColor.cgColor | ||
layer.cornerRadius = cornerRadius | ||
layer.borderWidth = borderWidth | ||
} | ||
|
||
func addUnderline() { | ||
let attributedString = NSMutableAttributedString(string: self.titleLabel?.text ?? "") | ||
attributedString.addAttribute( | ||
.underlineStyle, | ||
value: NSUnderlineStyle.single.rawValue, | ||
range: NSRange(location: 0, length: attributedString.length) | ||
) | ||
setAttributedTitle(attributedString, for: .normal) | ||
} | ||
} |
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,45 @@ | ||
// | ||
// UIFont+.swift | ||
// KkuMulKum | ||
// | ||
// Created by 김진웅 on 6/30/24. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIFont { | ||
static func pretendard(_ style: Pretendard) -> UIFont { | ||
return UIFont(name: style.weight, size: style.size) ?? .systemFont(ofSize: style.size) | ||
} | ||
|
||
enum Pretendard { | ||
case title01, title02 | ||
case head01, head02 | ||
case body01, body02, body03, body04, body05, body06 | ||
case caption01, caption02 | ||
case label01, label02 | ||
|
||
var weight: String { | ||
switch self { | ||
case .title01, .head01, .body01, .body03, .body05, .caption01, .label01: "Pretendard-SemiBold" | ||
case .title02, .head02, .body02, .body04, .body06, .caption02, .label02: "Pretendard-Regular" | ||
} | ||
} | ||
|
||
var size: CGFloat { | ||
switch self { | ||
case .title01, .title02: 24 | ||
case .head01, .head02: 22 | ||
case .body01, .body02: 18 | ||
case .body03, .body04: 16 | ||
case .body05, .body06: 14 | ||
case .caption01, .caption02: 12 | ||
case .label01, .label02: 10 | ||
} | ||
} | ||
|
||
var tracking: CGFloat { CGFloat(-2) / 100 * size } | ||
|
||
var leading: CGFloat { (1.6 - 1) * size } | ||
} | ||
} |
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,37 @@ | ||
// | ||
// UILabel+.swift | ||
// KkuMulKum | ||
// | ||
// Created by 김진웅 on 6/30/24. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UILabel { | ||
func setText(_ text: String, style: UIFont.Pretendard, color: UIColor) { | ||
attributedText = .pretendardString(text, style: style) | ||
textColor = color | ||
numberOfLines = 0 | ||
} | ||
|
||
func setHighlightText(_ words: String..., style: UIFont.Pretendard, color: UIColor? = nil) { | ||
guard let currentText = attributedText?.string else { return } | ||
let mutableAttributedString = NSMutableAttributedString( | ||
attributedString: attributedText ?? NSAttributedString() | ||
) | ||
let textColor = textColor ?? .black | ||
|
||
for word in words { | ||
let range = (currentText as NSString).range(of: word) | ||
|
||
if range.location != NSNotFound { | ||
let highlightedAttributes: [NSAttributedString.Key: Any] = [ | ||
.font: UIFont.pretendard(style), | ||
.foregroundColor: color ?? textColor | ||
] | ||
mutableAttributedString.addAttributes(highlightedAttributes, range: range) | ||
attributedText = mutableAttributedString | ||
} | ||
} | ||
} | ||
} |
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,21 @@ | ||
// | ||
// UIStackView+.swift | ||
// KkuMulKum | ||
// | ||
// Created by 김진웅 on 6/30/24. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIStackView { | ||
convenience init(axis: NSLayoutConstraint.Axis) { | ||
self.init(frame: .zero) | ||
self.axis = axis | ||
} | ||
|
||
func addArrangedSubviews(_ views: UIView...) { | ||
views.forEach { | ||
self.addArrangedSubview($0) | ||
} | ||
} | ||
} |
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,52 @@ | ||
// | ||
// UITextField+.swift | ||
// KkuMulKum | ||
// | ||
// Created by 김진웅 on 6/30/24. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UITextField { | ||
func addPadding(left: CGFloat? = nil, right: CGFloat? = nil) { | ||
if let left { | ||
leftView = UIView(frame: CGRect(x: 0, y: 0, width: left, height: 0)) | ||
leftViewMode = .always | ||
} | ||
|
||
if let right { | ||
rightView = UIView(frame: CGRect(x: 0, y: 0, width: right, height: 0)) | ||
rightViewMode = .always | ||
} | ||
} | ||
|
||
func setText( | ||
placeholder: String, | ||
textColor: UIColor, | ||
backgroundColor: UIColor, | ||
placeholderColor: UIColor, | ||
style: UIFont.Pretendard | ||
) { | ||
self.textColor = textColor | ||
self.backgroundColor = backgroundColor | ||
attributedPlaceholder = NSAttributedString( | ||
string: placeholder, | ||
attributes: [.foregroundColor: placeholderColor, .font: style, .kern: style.tracking] | ||
) | ||
self.attributedText = .pretendardString(style: style) | ||
} | ||
|
||
func setAutoType( | ||
autocapitalizationType: UITextAutocapitalizationType = .none, | ||
autocorrectionType: UITextAutocorrectionType = .no | ||
) { | ||
self.autocapitalizationType = autocapitalizationType | ||
self.autocorrectionType = autocorrectionType | ||
} | ||
|
||
func setLayer(borderWidth: CGFloat = 0, borderColor: UIColor, cornerRadius: CGFloat) { | ||
layer.borderColor = borderColor.cgColor | ||
layer.cornerRadius = cornerRadius | ||
layer.borderWidth = borderWidth | ||
} | ||
} |
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,27 @@ | ||
// | ||
// UIView+.swift | ||
// KkuMulKum | ||
// | ||
// Created by 김진웅 on 6/30/24. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIView { | ||
convenience init(backgroundColor: UIColor) { | ||
self.init(frame: .zero) | ||
self.backgroundColor = backgroundColor | ||
} | ||
|
||
func addSubviews(_ views: UIView...) { | ||
views.forEach { | ||
addSubview($0) | ||
} | ||
} | ||
|
||
func roundCorners(cornerRadius: CGFloat, maskedCorners: CACornerMask) { | ||
clipsToBounds = true | ||
layer.cornerRadius = cornerRadius | ||
layer.maskedCorners = CACornerMask(arrayLiteral: maskedCorners) | ||
} | ||
} |
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 @@ | ||
// | ||
// ReuseIdentifiable.swift | ||
// KkuMulKum | ||
// | ||
// Created by 김진웅 on 6/30/24. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol ReuseIdentifiable {} | ||
|
||
extension ReuseIdentifiable { | ||
static var reuseIdentifier: String { String(describing: self) } | ||
} |
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 @@ | ||
// | ||
// Screen.swift | ||
// KkuMulKum | ||
// | ||
// Created by 김진웅 on 6/30/24. | ||
// | ||
|
||
import UIKit | ||
|
||
enum Screen { | ||
static func width(_ value: CGFloat) -> CGFloat { | ||
let screenWidth = UIScreen.main.bounds.width | ||
let designWidth: CGFloat = 375.0 | ||
return screenWidth / designWidth * value | ||
} | ||
|
||
static func height(_ value: CGFloat) -> CGFloat { | ||
let screenHeight = UIScreen.main.bounds.height | ||
let designHeight: CGFloat = 812.0 | ||
return screenHeight / designHeight * value | ||
} | ||
} |