Skip to content

Commit

Permalink
[Refactor] #243 - 버튼 attribute 설정 함수 추가 및 중복 코드 함수화
Browse files Browse the repository at this point in the history
  • Loading branch information
yungu0010 committed Mar 20, 2024
1 parent 92b2cc8 commit 88d71c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 39 deletions.
13 changes: 13 additions & 0 deletions iOS-NOTTODO/iOS-NOTTODO/Global/Extensions/UIButton+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,17 @@ extension UIButton {
)
setAttributedTitle(attributedString, for: .normal)
}

func setUnderlines(target: [String]) {
guard let title = titleLabel?.text else { return }
let attributedString = NSMutableAttributedString(string: title)
target.forEach {
let range = (title as NSString).range(of: $0)
attributedString.addAttribute(
.underlineStyle,
value: NSUnderlineStyle.single.rawValue,
range: range)
}
setAttributedTitle(attributedString, for: .normal)
}
}
42 changes: 3 additions & 39 deletions iOS-NOTTODO/iOS-NOTTODO/Presentation/Auth/AuthViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ final class AuthViewController: UIViewController {
private var appleLoginButton = AuthButton(frame: .zero, title: I18N.appleLogin, icon: .appleLogo, color: .white)

private var moreButton = UIButton()
private var conditionButton = UIButton()
private var personalInfoButton = UIButton()

// MARK: - init
init(coordinator: AuthCoordinator) {
Expand Down Expand Up @@ -64,25 +62,15 @@ extension AuthViewController {
$0.textColor = .white
$0.text = I18N.loginMain
$0.numberOfLines = 2

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = $0.font.lineHeight * 0.2

let attributedText = NSAttributedString(string: $0.text ?? "", attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
$0.attributedText = attributedText
$0.setLineSpacing(lineSpacing: $0.font.lineHeight * 0.2)
}

loginSubLabel.do {
$0.font = .Pretendard(.medium, size: 16)
$0.textColor = .gray4
$0.text = I18N.loginSub
$0.numberOfLines = 3

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = $0.font.lineHeight * 0.2

let attributedText = NSAttributedString(string: $0.text ?? "", attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
$0.attributedText = attributedText
$0.setLineSpacing(lineSpacing: $0.font.lineHeight * 0.2)
}

kakaoLoginImageView.image = .kakaoLoginLabel
Expand All @@ -94,29 +82,14 @@ extension AuthViewController {
$0.setTitle(I18N.moreAuth, for: .normal)
$0.setTitleColor(.gray4, for: .normal)
$0.titleLabel?.font = .Pretendard(.regular, size: 12)
}

conditionButton.do {
$0.setTitle(I18N.condition, for: .normal)
$0.setTitleColor(.gray4, for: .normal)
$0.titleLabel?.font = .Pretendard(.regular, size: 12)
$0.setUnderline()
$0.addTarget(self, action: #selector(moreButtonTapped), for: .touchUpInside)
}

personalInfoButton.do {
$0.setTitle(I18N.personalInfo, for: .normal)
$0.setTitleColor(.gray4, for: .normal)
$0.titleLabel?.font = .Pretendard(.regular, size: 12)
$0.setUnderline()
$0.setUnderlines(target: [I18N.condition, I18N.personalInfo])
$0.addTarget(self, action: #selector(moreButtonTapped), for: .touchUpInside)
}
}

private func setLayout() {

view.addSubviews(loginMainLabel, loginSubLabel, kakaoLoginImageView, kakaoLoginButton, appleLoginButton, moreButton)
moreButton.addSubviews(conditionButton, personalInfoButton)

loginMainLabel.snp.makeConstraints {
$0.top.equalToSuperview().offset(155.adjusted)
Expand Down Expand Up @@ -151,15 +124,6 @@ extension AuthViewController {
$0.width.equalTo(189.adjusted)
$0.height.equalTo(37.adjusted)
}

conditionButton.snp.makeConstraints {
$0.centerY.leading.equalToSuperview()
}

personalInfoButton.snp.makeConstraints {
$0.centerY.trailing.equalToSuperview()
}

}

// MARK: - @objc Methods
Expand Down

0 comments on commit 88d71c7

Please sign in to comment.