-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat] #210 Custom banner
- Loading branch information
Showing
7 changed files
with
292 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
Smeem-iOS/Smeem-iOS/Global/UIComponents/CustomBannerView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// | ||
// CustomBannerView.swift | ||
// Smeem-iOS | ||
// | ||
// Created by Joon Baek on 2024/07/09. | ||
// | ||
|
||
import UIKit | ||
import Combine | ||
|
||
import SnapKit | ||
|
||
final class CustomBannerView: BaseView { | ||
|
||
private (set) var closeButtonTapped = PassthroughSubject<Void, Never>() | ||
private var cancelBag = Set<AnyCancellable>() | ||
|
||
private let titleLabel: UILabel = { | ||
let label = UILabel() | ||
label.font = .s1 | ||
label.textColor = .smeemBlack | ||
// label.text = "헤더레이블" | ||
return label | ||
}() | ||
|
||
private let bodyLabel: UILabel = { | ||
let label = UILabel() | ||
label.font = .c3 | ||
label.textColor = .smeemBlack | ||
// label.text = "바디레이블" | ||
return label | ||
}() | ||
|
||
private lazy var closeButton: UIButton = { | ||
let button = UIButton() | ||
button.setImage(Constant.Image.icnCancelGrey, for: .normal) | ||
button.tintColor = .gray200 | ||
return button | ||
}() | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
|
||
setUI() | ||
setLayout() | ||
subscribeButtonEvent() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
override func setUI() { | ||
backgroundColor = .gray100 | ||
layer.cornerRadius = 10 | ||
} | ||
} | ||
|
||
extension CustomBannerView { | ||
private func setLayout() { | ||
addSubviews(titleLabel, bodyLabel, closeButton) | ||
|
||
titleLabel.snp.makeConstraints { make in | ||
make.top.equalToSuperview().offset(22) | ||
make.leading.equalToSuperview().offset(18) | ||
} | ||
|
||
bodyLabel.snp.makeConstraints { make in | ||
make.top.equalTo(titleLabel.snp.bottom).offset(4) | ||
make.leading.equalTo(titleLabel) | ||
} | ||
|
||
closeButton.snp.makeConstraints { make in | ||
make.centerY.equalToSuperview() | ||
make.trailing.equalToSuperview() | ||
make.size.equalTo(40) | ||
} | ||
} | ||
|
||
private func subscribeButtonEvent() { | ||
closeButton.tapPublisher.sink { [weak self] in | ||
self?.closeButtonTapped.send() | ||
} | ||
.store(in: &cancelBag) | ||
} | ||
|
||
func setLabelText(with title: String, body: String) { | ||
DispatchQueue.main.async {[weak self] in | ||
self?.titleLabel.text = title | ||
self?.bodyLabel.text = body | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.