diff --git a/weather-app/weather-app/Presentation/Detail/Cell/DetailCollectionViewCell.swift b/weather-app/weather-app/Presentation/Detail/Cell/DetailCollectionViewCell.swift index bc55756..6c05e48 100644 --- a/weather-app/weather-app/Presentation/Detail/Cell/DetailCollectionViewCell.swift +++ b/weather-app/weather-app/Presentation/Detail/Cell/DetailCollectionViewCell.swift @@ -57,20 +57,11 @@ class DetailCollectionViewCell: UICollectionViewCell { } private func setStyle() { - locationLabel.do { - $0.font = .sfRegular(size: 36) - $0.textColor = .white - } + locationLabel.setupLabel(font: .sfRegular(size: 36), textColor: .white) - temperatureLabel.do { - $0.font = .sfThin(size: 102) - $0.textColor = .white - } + temperatureLabel.setupLabel(font: .sfThin(size: 102), textColor: .white) - conditionLabel.do { - $0.font = .sfRegular(size: 24) - $0.textColor = .white - } + conditionLabel.setupLabel(font: .sfRegular(size: 24), textColor: .white) temperatureStackView.do { $0.axis = .horizontal @@ -78,15 +69,8 @@ class DetailCollectionViewCell: UICollectionViewCell { $0.distribution = .equalSpacing } - minTemperatureLabel.do { - $0.font = .sfMedium(size: 20) - $0.textColor = .white - } - - maxTemperatureLabel.do { - $0.font = .sfMedium(size: 20) - $0.textColor = .white - } - + minTemperatureLabel.setupLabel(font: .sfMedium(size: 20), textColor: .white) + + maxTemperatureLabel.setupLabel(font: .sfMedium(size: 20), textColor: .white) } } diff --git a/weather-app/weather-app/Presentation/Detail/Cell/TenDaysForecastCollectionViewCell.swift b/weather-app/weather-app/Presentation/Detail/Cell/TenDaysForecastCollectionViewCell.swift index fa00bc8..9446765 100644 --- a/weather-app/weather-app/Presentation/Detail/Cell/TenDaysForecastCollectionViewCell.swift +++ b/weather-app/weather-app/Presentation/Detail/Cell/TenDaysForecastCollectionViewCell.swift @@ -67,10 +67,7 @@ class TenDaysForecastCollectionViewCell: UICollectionViewCell { private func setStyle() { - dayNameLabel.do { - $0.font = .sfMedium(size: 22) - $0.textColor = .white - } + dayNameLabel.setupLabel(font: .sfMedium(size: 22), textColor: .white) conditionStackView.do { $0.axis = .vertical @@ -82,20 +79,11 @@ class TenDaysForecastCollectionViewCell: UICollectionViewCell { $0.tintColor = .white } - precipPercentLabel.do { - $0.font = .sfMedium(size: 15) - $0.textColor = UIColor(red: 0.506, green: 0.812, blue: 0.98, alpha: 1) - } - - minTempLabel.do { - $0.font = .sfMedium(size: 22) - $0.textColor = UIColor(red: 1, green: 1, blue: 1, alpha: 1) - } + precipPercentLabel.setupLabel(font: .sfMedium(size: 15), textColor: UIColor(red: 0.506, green: 0.812, blue: 0.98, alpha: 1)) + + minTempLabel.setupLabel(font: .sfMedium(size: 22), textColor: UIColor(red: 1, green: 1, blue: 1, alpha: 1)) - maxTempLabel.do { - $0.font = .sfMedium(size: 22) - $0.textColor = UIColor(red: 1, green: 1, blue: 1, alpha: 1) - } + maxTempLabel.setupLabel(font: .sfMedium(size: 22), textColor: UIColor(red: 1, green: 1, blue: 1, alpha: 1)) } func bindData(data: TenDaysForecastData) { diff --git a/weather-app/weather-app/Presentation/Detail/Cell/TodayForecastCollectionViewCell.swift b/weather-app/weather-app/Presentation/Detail/Cell/TodayForecastCollectionViewCell.swift index a58f6c9..7edd8f5 100644 --- a/weather-app/weather-app/Presentation/Detail/Cell/TodayForecastCollectionViewCell.swift +++ b/weather-app/weather-app/Presentation/Detail/Cell/TodayForecastCollectionViewCell.swift @@ -43,17 +43,9 @@ class TodayForecastCollectionViewCell: UICollectionViewCell { $0.distribution = .equalSpacing } - timeLabel.do { - $0.font = .sfMedium(size: 17) - $0.textColor = .white - $0.textAlignment = .center - } + timeLabel.setupLabel(font: .sfMedium(size: 17), textColor: .white) - temperatureLabel.do { - $0.font = .sfMedium(size: 17) - $0.textColor = .white - $0.textAlignment = .center - } + temperatureLabel.setupLabel(font: .sfMedium(size: 17), textColor: .white) self.contentView.do { $0.backgroundColor = .clear diff --git a/weather-app/weather-app/Presentation/Detail/View/TenDaysCollectionHeaderView.swift b/weather-app/weather-app/Presentation/Detail/View/TenDaysCollectionHeaderView.swift index a3b3e97..3f9ab85 100644 --- a/weather-app/weather-app/Presentation/Detail/View/TenDaysCollectionHeaderView.swift +++ b/weather-app/weather-app/Presentation/Detail/View/TenDaysCollectionHeaderView.swift @@ -46,10 +46,6 @@ class TenDaysCollectionHeaderView: UICollectionReusableView { $0.tintColor = UIColor.lightGray } - headerTextLabel.do { - $0.text = "10일간의 일기예보" - $0.font = .sfMedium(size: 15) - $0.textColor = UIColor.lightGray - } + headerTextLabel.setupLabel(font: .sfMedium(size: 15), text:"10일간의 일기예보", textColor: UIColor.lightGray ) } } diff --git a/weather-app/weather-app/Presentation/Detail/View/TodayCollectionHeaderView.swift b/weather-app/weather-app/Presentation/Detail/View/TodayCollectionHeaderView.swift index b01b98d..50647b3 100644 --- a/weather-app/weather-app/Presentation/Detail/View/TodayCollectionHeaderView.swift +++ b/weather-app/weather-app/Presentation/Detail/View/TodayCollectionHeaderView.swift @@ -46,10 +46,6 @@ class TodayCollectionHeaderView: UICollectionReusableView { $0.tintColor = UIColor.lightGray } - headerTextLabel.do { - $0.text = "시간별 일기예보" - $0.font = .sfMedium(size: 15) - $0.textColor = UIColor.lightGray - } + headerTextLabel.setupLabel(font: .sfMedium(size: 15), text: "시간별 일기예보", textColor: UIColor.lightGray) } } diff --git a/weather-app/weather-app/Presentation/List/Cell/CardCollectionViewCell.swift b/weather-app/weather-app/Presentation/List/Cell/CardCollectionViewCell.swift index fc90151..6a86834 100644 --- a/weather-app/weather-app/Presentation/List/Cell/CardCollectionViewCell.swift +++ b/weather-app/weather-app/Presentation/List/Cell/CardCollectionViewCell.swift @@ -84,35 +84,12 @@ class CardCollectionViewCell: UICollectionViewCell { $0.isUserInteractionEnabled = true } - location.do { - $0.font = .sfBold(size: 24) - $0.textColor = .white - } - - currentTime.do { - $0.font = .sfMedium(size: 17) - $0.textColor = .white - } - - currentCondition.do { - $0.font = .sfMedium(size: 16) - $0.textColor = .white - } - - maxTemperature.do { - $0.font = .sfMedium(size: 15) - $0.textColor = .white - } - - minTemperature.do { - $0.font = .sfMedium(size: 15) - $0.textColor = .white - } - - currentTemperature.do { - $0.font = .sfLight(size: 52) - $0.textColor = .white - } + location.setupLabel(font: .sfBold(size: 24), textColor: .white) + currentTime.setupLabel(font: .sfMedium(size: 17), textColor: .white) + currentCondition.setupLabel(font: .sfMedium(size: 16), textColor: .white) + maxTemperature.setupLabel(font: .sfMedium(size: 15), textColor: .white) + minTemperature.setupLabel(font: .sfMedium(size: 15), textColor: .white) + currentTemperature.setupLabel(font: .sfLight(size: 52), textColor: .white) } func configureCell(data: WeatherListModel) { diff --git a/weather-app/weather-app/Presentation/List/View/WeatherCardView.swift b/weather-app/weather-app/Presentation/List/View/WeatherCardView.swift index 22068e2..b4242bf 100644 --- a/weather-app/weather-app/Presentation/List/View/WeatherCardView.swift +++ b/weather-app/weather-app/Presentation/List/View/WeatherCardView.swift @@ -75,39 +75,12 @@ class WeatherCardView: UIButton { $0.layer.cornerRadius = 16 $0.isUserInteractionEnabled = true } - - myLocation.do { - $0.text = "나의 위치" - $0.font = .sfBold(size: 24) - $0.textColor = .white - } - - currentLocation.do { - $0.text = "고양시" - $0.font = .sfMedium(size: 17) - $0.textColor = .white - } - - currentCondition.do { - $0.text = "흐림" - $0.font = .sfMedium(size: 16) - $0.textColor = .white - } - - maxTemperature.do { - $0.text = "최고:29°" - $0.font = .sfMedium(size: 15) - $0.textColor = .white - } - minTemperature.do { - $0.text = "최저:15°" - $0.font = .sfMedium(size: 15) - $0.textColor = .white - } - currentTemperature.do { - $0.text = "21°" - $0.font = .sfLight(size: 52) - $0.textColor = .white - } + + myLocation.setupLabel(font: .sfBold(size: 24), textColor: .white) + currentLocation.setupLabel(font: .sfMedium(size: 17), textColor: .white) + currentCondition.setupLabel(font: .sfMedium(size: 16), textColor: .white) + maxTemperature.setupLabel(font: .sfMedium(size: 15), textColor: .white) + minTemperature.setupLabel(font: .sfMedium(size: 15), textColor: .white) + currentTemperature.setupLabel(font: .sfLight(size: 52), textColor: .white) } } diff --git a/weather-app/weather-app/Resources/Extensions/UILabel+.swift b/weather-app/weather-app/Resources/Extensions/UILabel+.swift new file mode 100644 index 0000000..2496a2b --- /dev/null +++ b/weather-app/weather-app/Resources/Extensions/UILabel+.swift @@ -0,0 +1,62 @@ +// +// UILabel+.swift +// weather-app +// +// Created by 윤영서 on 12/15/23. +// + +import UIKit + +extension UILabel { + + func highlightText(forText: String, forColor: UIColor) { + guard let labelText = self.text else { return } + let attributedString = NSMutableAttributedString(string: labelText) + + let range = (labelText as NSString).range(of: forText) + attributedString.addAttribute(.foregroundColor, value: forColor, range: range) + + self.attributedText = attributedString + } + + func underLineText(forText: [String]) { + guard let labelText = self.text else { return } + + let underLineText = NSMutableAttributedString(string: labelText) + + for text in forText { + let range = (labelText as NSString).range(of: text) + underLineText.addAttribute(NSAttributedString.Key.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: range) + } + + self.attributedText = underLineText + } + + func labelWithImg(composition: NSAttributedString...) { + let attributedString = NSMutableAttributedString() + for i in composition { + attributedString.append(i) + attributedString.append(NSAttributedString(string: " ")) + } + self.attributedText = attributedString + } + + func setupLabel(font: UIFont, text: String? = nil, textColor: UIColor, alignment: NSTextAlignment = .center) { + self.font = font + self.text = text + self.textColor = textColor + self.textAlignment = alignment + } + + func setupRoundedLabel(text: String, font: UIFont, textColor: UIColor, alignment: NSTextAlignment, bgColor: UIColor, borderColor: UIColor, borderWidth: CGFloat, radius: CGFloat) { + self.text = text + self.font = font + self.textColor = textColor + self.textAlignment = alignment + self.backgroundColor = bgColor + self.layer.borderColor = borderColor.cgColor + self.layer.borderWidth = borderWidth + self.layer.cornerRadius = radius + self.layer.masksToBounds = true + } +}