Skip to content

Commit

Permalink
[Chore] sopt-makers#151 - userInfoLabel에 attributedText 적용하는 함수 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
lsj8706 committed Apr 15, 2023
1 parent 3dd41a1 commit 405db2b
Showing 1 changed file with 23 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,44 +57,35 @@ extension UserHistoryHeaderView {
if let name = name, let months = months {
let text = (userType == .visitor) ? I18N.Main.encourage : I18N.Main.userHistory(name: name, months: months)

let attributedText = NSMutableAttributedString(string: text,
attributes: [
.foregroundColor: DSKitAsset.Colors.white100.color,
.font: UIFont.Main.display2
])
attributedText.addAttribute(.font,
value: UIFont.Main.display1,
range: (text as NSString).range(of:"\(name)"))

attributedText.addAttribute(.font,
value: UIFont.Main.display1,
range: (text as NSString).range(of:I18N.Main.hello))

self.userInfoLabel.attributedText = attributedText
setAttributedTextToUserInfoLabel(text: text, name: name)
} else {
if userType == .visitor {
let text = I18N.Main.encourage
let attributedText = NSMutableAttributedString(string: text,
attributes: [
.foregroundColor: DSKitAsset.Colors.white100.color,
.font: UIFont.Main.display2
])
attributedText.addAttribute(.font,
value: UIFont.Main.display1,
range: (text as NSString).range(of: I18N.Main.hello))
self.userInfoLabel.attributedText = attributedText
setAttributedTextToUserInfoLabel(text: text, name: nil)
} else if userType == .inactive {
let text = I18N.Main.welcome
let attributedText = NSMutableAttributedString(string: text,
attributes: [
.foregroundColor: DSKitAsset.Colors.white100.color,
.font: UIFont.Main.display2
])
attributedText.addAttribute(.font,
value: UIFont.Main.display1,
range: (text as NSString).range(of: I18N.Main.hello))
self.userInfoLabel.attributedText = attributedText
setAttributedTextToUserInfoLabel(text: text, name: nil)
}
}
}

func setAttributedTextToUserInfoLabel(text: String, name: String?) {
let attributedText = NSMutableAttributedString(string: text,
attributes: [
.foregroundColor: DSKitAsset.Colors.white100.color,
.font: UIFont.Main.display2
])

if let name = name {
attributedText.addAttribute(.font,
value: UIFont.Main.display1,
range: (text as NSString).range(of:"\(name)"))
}

attributedText.addAttribute(.font,
value: UIFont.Main.display1,
range: (text as NSString).range(of:I18N.Main.hello))

self.userInfoLabel.attributedText = attributedText
}
}

0 comments on commit 405db2b

Please sign in to comment.