-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Week2] 토스 앱 상세페이지 구현 #7
base: main
Are you sure you want to change the base?
Changes from all commits
7e0dd40
faa8441
83f92ee
7d62a2a
c8b4493
b218f39
00d03f9
1ee012b
6ccf3c2
cb3c075
329956e
3e14b8c
8be6990
8d874ec
25af2b5
5b8baf6
e5b04f7
38591f7
8caf1f2
4fac0e4
13c9c30
c791371
0d0c69c
8675705
35a5bbd
ab70aa1
fe53053
f71d19d
afcc9f3
739ec2d
c1a001f
ee0dcb3
abe707f
27994c2
50d1a02
4d227f0
4b557dd
714216e
468fde9
6b4a67a
9c76966
de8ae7f
e80822d
c5c8aee
dd8f4e0
40b1651
6ee36ee
2bdba1f
683696c
b2fc57a
3e75b73
1cdafd4
14a08bf
f0d299c
ccda275
4ed7137
89becd1
94624e8
fd2d488
5cdce7e
317f59e
b7d0366
d0e1cc8
607f6fd
b6b4b7b
fa881ac
ae4fd34
7218788
6a2b25c
da9fce4
1baebe8
cb0550e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Date+Extension.swift | ||
// 35-seminar | ||
// | ||
// Created by 김유림 on 10/25/24. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Date { | ||
static func form(year: Int, month: Int, day: Int) -> Date? { | ||
var dateComponents = DateComponents() | ||
dateComponents.year = year | ||
dateComponents.month = month | ||
dateComponents.day = day | ||
|
||
return Calendar.current.date(from: dateComponents) | ||
} | ||
|
||
static func formattedDate(date: Date?) -> String { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 매개변수로 받지 않고 static이 아닌 Date의 함수로 작동할 수 있도록 self를 이용하면 더 깔끔할 것 같아요 😄 |
||
guard let inputDate = date else { return "날짜 없음" } | ||
|
||
let currentYear = Calendar.current.component(.year, from: Date()) | ||
let inputYear = Calendar.current.component(.year, from: inputDate) | ||
let yearDifference = currentYear - inputYear | ||
|
||
guard yearDifference > 0 else { | ||
let dateFormatter = DateFormatter() | ||
dateFormatter.dateFormat = "M월 d" | ||
return dateFormatter.string(from: inputDate) | ||
} | ||
|
||
return "\(yearDifference)년 전" | ||
} | ||
} |
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Button의 속성을 모두 컨트롤 할 수 있는 함수인 것 같아요. |
||
title: String? = nil, | ||
fontSize: CGFloat = 15, | ||
fontWeight: UIFont.Weight = .regular, | ||
systemName: String = "", | ||
pointSize: CGFloat? = nil, | ||
symbolWeight: UIImage.SymbolWeight = .unspecified, | ||
cornerStyle: UIButton.Configuration.CornerStyle? = nil, | ||
foregroundColor: UIColor = .tintColor, | ||
backgroundColor: UIColor = .clear, | ||
removeContentInsets: Bool = false, | ||
for state: UIControl.State = .normal) { | ||
|
||
var config = { | ||
switch configType { | ||
case .plain: | ||
return UIButton.Configuration.plain() | ||
case .filled: | ||
return UIButton.Configuration.filled() | ||
} | ||
}() | ||
|
||
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) | ||
} | ||
|
||
config.image = UIImage.configureImage(systemName: systemName, pointSize: pointSize, symbolWeight: symbolWeight) | ||
|
||
if let cornerStyle = cornerStyle { | ||
config.cornerStyle = cornerStyle | ||
} | ||
|
||
config.baseForegroundColor = foregroundColor | ||
config.baseBackgroundColor = backgroundColor | ||
|
||
if removeContentInsets { | ||
config.contentInsets = .zero | ||
} | ||
|
||
self.configuration = config | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// UIImageView+Extension.swift | ||
// 35-seminar | ||
// | ||
// Created by 김유림 on 10/25/24. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIImage { | ||
class func configureImage(systemName: String, pointSize: CGFloat? = nil, symbolWeight: UIImage.SymbolWeight) -> UIImage? { | ||
if let pointSize = pointSize { | ||
let symbolConfig = UIImage.SymbolConfiguration(pointSize: pointSize, weight: symbolWeight) | ||
return UIImage(systemName: systemName, withConfiguration: symbolConfig) | ||
} | ||
|
||
let symbolConfig = UIImage.SymbolConfiguration(weight: symbolWeight) | ||
return UIImage(systemName: systemName, withConfiguration: symbolConfig) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// UILabel+Extension.swift | ||
// 35-seminar | ||
// | ||
// Created by 김유림 on 10/15/24. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UILabel { | ||
func configureLabel(alignment: NSTextAlignment = .left, color: UIColor = .label, size: CGFloat, weight: UIFont.Weight, text: String? = nil, numberOfLines: Int = 1) { | ||
self.textAlignment = alignment | ||
self.textColor = color | ||
self.font = .systemFont(ofSize: size, weight: weight) | ||
self.text = text | ||
self.numberOfLines = numberOfLines | ||
} | ||
|
||
func setLineSpacing(_ lineSpacing: CGFloat) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UILabel에 줄 간격을 설정하는 방법으로 좋은 것 같아요! |
||
guard let text = self.text else { return } | ||
let paragraphStyle = NSMutableParagraphStyle() | ||
paragraphStyle.lineSpacing = lineSpacing | ||
self.attributedText = NSAttributedString(string: text, attributes: [.paragraphStyle: paragraphStyle]) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Date형식을 생성하는 함수라고 생각하는데
제가 이해한 게 맞다면 init으로 구현하는 것도 고려해보시면 좋을 것 같아요!