-
Notifications
You must be signed in to change notification settings - Fork 0
[FIX] 서브지역 카테고리 라벨 상단이 짤리던 이슈 수정 #137
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
Changes from 3 commits
9b7b191
64fe835
304ae77
9b804a5
b45ef4c
0c63c1f
43bbd14
66e0d41
ea00043
29ab38f
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 |
|---|---|---|
| @@ -1,88 +1,130 @@ | ||
| import Infrastructure | ||
| import SnapKit | ||
| import Then | ||
| import UIKit | ||
|
|
||
| final class BalloonChipCell: UICollectionViewCell { | ||
| static let identifier = "BalloonChipCell" | ||
|
|
||
| private let button: PPButton = { | ||
| let button = PPButton( | ||
| style: .secondary, | ||
| text: "", | ||
| font: .korFont(style: .medium, size: 11), | ||
| cornerRadius: 15 | ||
| ) | ||
|
|
||
| button.titleLabel?.lineBreakMode = .byTruncatingTail | ||
| button.titleLabel?.adjustsFontSizeToFitWidth = false | ||
| return button | ||
| }() | ||
|
|
||
| override init(frame: CGRect) { | ||
| super.init(frame: frame) | ||
| contentView.addSubview(button) | ||
| setupLayout() | ||
| } | ||
|
|
||
| required init?(coder: NSCoder) { | ||
| fatalError("init(coder:) has not been implemented") | ||
| } | ||
|
|
||
| private func setupLayout() { | ||
| button.snp.makeConstraints { make in | ||
| make.edges.equalToSuperview() | ||
| } | ||
| } | ||
|
|
||
| func configure(with title: String, isSelected: Bool) { | ||
| button.setTitle(title, for: .normal) | ||
| if isSelected { | ||
| let checkImage = UIImage(named: "icon_check_white")?.withRenderingMode(.alwaysOriginal) | ||
| let resizedImage = checkImage?.resize(to: CGSize(width: 16, height: 16)) | ||
| button.setImage(resizedImage, for: .normal) | ||
| button.semanticContentAttribute = .forceRightToLeft | ||
| button.imageEdgeInsets = UIEdgeInsets(top: 0, left: 2, bottom: 0, right: 0) | ||
| button.contentEdgeInsets = UIEdgeInsets(top: 4, left: 10, bottom: 6, right: 12) | ||
| button.setBackgroundColor(.blu500, for: .normal) | ||
| button.setTitleColor(.white, for: .normal) | ||
| button.layer.borderWidth = 0 | ||
| button.titleLabel?.font = .korFont(style: .bold, size: 11) | ||
|
|
||
| } else { | ||
| button.setImage(nil, for: .normal) | ||
| button.semanticContentAttribute = .unspecified | ||
| button.imageEdgeInsets = .zero | ||
| button.contentEdgeInsets = UIEdgeInsets(top: 4, left: 12, bottom: 6, right: 12) | ||
| button.setBackgroundColor(.white, for: .normal) | ||
| button.setTitleColor(.g400, for: .normal) | ||
| button.layer.borderWidth = 1 | ||
| button.layer.borderColor = UIColor.g200.cgColor | ||
| button.titleLabel?.font = .korFont(style: .medium, size: 11) | ||
|
|
||
| } | ||
| } | ||
|
|
||
| private var currentAction: UIAction? | ||
|
|
||
| var buttonAction: (() -> Void)? { | ||
| didSet { | ||
| if let oldAction = currentAction { | ||
| button.removeAction(oldAction, for: .touchUpInside) | ||
| } | ||
|
|
||
| let action = UIAction { [weak self] _ in | ||
| self?.buttonAction?() | ||
| } | ||
| button.addAction(action, for: .touchUpInside) | ||
| currentAction = action | ||
| } | ||
| } | ||
| static let identifier = "BalloonChipCell" | ||
|
||
|
|
||
| private enum Constant { | ||
|
Member
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. 사용할 값들을 Constant로 빼서 사용하는 룰!! 적용된 걸 보니 깔끔해서 좋습니다 :> |
||
| static let verticalInset: CGFloat = 6 | ||
| static let selectedLeftInset: CGFloat = 10 | ||
| static let normalLeftInset: CGFloat = 12 | ||
| static let rightInset: CGFloat = 12 | ||
| static let checkIconSize: CGSize = .init(width: 16, height: 16) | ||
| static let baselineOffset: CGFloat = -1 | ||
| static let fontSize: CGFloat = 11 | ||
| } | ||
|
|
||
| private let button = PPButton( | ||
| style: .secondary, | ||
| text: "", | ||
| font: .korFont(style: .medium, size: Constant.fontSize), | ||
| cornerRadius: 15 | ||
| ).then { | ||
| $0.titleLabel?.lineBreakMode = .byTruncatingTail | ||
| $0.titleLabel?.adjustsFontSizeToFitWidth = false | ||
| } | ||
|
|
||
| private var currentAction: UIAction? | ||
|
|
||
| override init(frame: CGRect) { | ||
| super.init(frame: frame) | ||
| contentView.addSubview(button) | ||
| setupLayout() | ||
| } | ||
|
|
||
| required init?(coder: NSCoder) { | ||
| fatalError("init(coder:) has not been implemented") | ||
| } | ||
|
|
||
| private func setupLayout() { | ||
| button.snp.makeConstraints { make in | ||
| make.edges.equalToSuperview() | ||
| } | ||
| } | ||
|
|
||
| func configure(with title: String, isSelected: Bool) { | ||
| let attributedTitle = NSMutableAttributedString(string: title).then { | ||
| $0.addAttribute( | ||
| .baselineOffset, | ||
| value: Constant.baselineOffset, | ||
| range: NSRange(location: .zero, length: $0.length) | ||
| ) | ||
| } | ||
|
|
||
| if isSelected { | ||
| let checkImage = UIImage(named: "icon_check_white")?.withRenderingMode(.alwaysOriginal).resize(to: Constant.checkIconSize) | ||
|
|
||
| button.then { | ||
| $0.setImage(checkImage, for: .normal) | ||
| $0.semanticContentAttribute = .forceRightToLeft | ||
| $0.imageEdgeInsets = .init(top: .zero, left: 1, bottom: .zero, right: .zero) | ||
| $0.contentEdgeInsets = .init( | ||
| top: Constant.verticalInset, | ||
| left: Constant.selectedLeftInset, | ||
| bottom: Constant.verticalInset, | ||
| right: Constant.rightInset | ||
| ) | ||
| $0.setBackgroundColor(.blu500, for: .normal) | ||
| $0.setTitleColor(.white, for: .normal) | ||
| $0.layer.borderWidth = .zero | ||
| } | ||
|
|
||
| attributedTitle.addAttribute( | ||
| .font, | ||
| value: UIFont.korFont(style: .bold, size: Constant.fontSize)!, | ||
| range: NSRange(location: .zero, length: attributedTitle.length) | ||
| ) | ||
| } else { | ||
| button.then { | ||
| $0.setImage(nil, for: .normal) | ||
| $0.semanticContentAttribute = .unspecified | ||
| $0.imageEdgeInsets = .zero | ||
| $0.contentEdgeInsets = .init( | ||
| top: Constant.verticalInset, | ||
| left: Constant.normalLeftInset, | ||
| bottom: Constant.verticalInset, | ||
| right: Constant.rightInset | ||
| ) | ||
| $0.setBackgroundColor(.white, for: .normal) | ||
| $0.setTitleColor(.g400, for: .normal) | ||
| $0.layer.borderWidth = 1 | ||
| $0.layer.borderColor = UIColor.g200.cgColor | ||
| } | ||
|
|
||
| attributedTitle.addAttribute( | ||
| .font, | ||
| value: UIFont.korFont(style: .medium, size: Constant.fontSize)!, | ||
| range: NSRange(location: .zero, length: attributedTitle.length) | ||
| ) | ||
| } | ||
|
|
||
| self.button.setAttributedTitle(attributedTitle, for: .normal) | ||
| } | ||
|
|
||
| var buttonAction: (() -> Void)? { | ||
| didSet { | ||
| if let oldAction = currentAction { | ||
| self.button.removeAction(oldAction, for: .touchUpInside) | ||
| } | ||
|
|
||
| let action = UIAction { [weak self] _ in | ||
| guard let self = self else { return } | ||
| self.buttonAction?() | ||
| } | ||
|
|
||
| self.button.addAction(action, for: .touchUpInside) | ||
| self.currentAction = action | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension UIImage { | ||
| func resize(to size: CGSize) -> UIImage? { | ||
| UIGraphicsBeginImageContextWithOptions(size, false, 0.0) | ||
| defer { UIGraphicsEndImageContext() } | ||
| draw(in: CGRect(origin: .zero, size: size)) | ||
| return UIGraphicsGetImageFromCurrentImageContext() | ||
| } | ||
| func resize(to size: CGSize) -> UIImage? { | ||
| UIGraphicsBeginImageContextWithOptions(size, false, 0.0) | ||
| defer { UIGraphicsEndImageContext() } | ||
| self.draw(in: CGRect(origin: .zero, size: size)) | ||
| return UIGraphicsGetImageFromCurrentImageContext() | ||
| } | ||
| } | ||
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.
import 순서 및 띄워쓰기를 팀 룰에 맞게 수정하면 좋을 것 같습니다 :>