Skip to content

Commit

Permalink
[Feat] #28 - 게시글 투명도 버튼 팝업 뷰 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonsu0-0 committed Jan 11, 2024
1 parent 2a0cec2 commit a9a587c
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 38 deletions.
7 changes: 7 additions & 0 deletions DontBe-iOS/DontBe-iOS/Global/Literals/StringLiterals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,11 @@ enum StringLiterals {
enum MyPage {
static let MyPageNavigationTitle = "마이"
}

enum Home {
static let transparentPopupTitleLabel = "투명도 주기"
static let transparentPopupContentLabel = "지금 누르신 투명도 기능이 Don’t be를 더 온화한 커뮤니티로 만들기 위한 일이겠죠?"
static let transparentPopupLefteftButtonTitle = "조금 더 고민하기"
static let transparentPopupRightButtonTitle = "네, 맞아요"
}
}
104 changes: 81 additions & 23 deletions DontBe-iOS/DontBe-iOS/Presentation/Helpers/DontBePopupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protocol DontBePopupDelegate: AnyObject {
}

final class DontBePopupView: UIView {

// MARK: - Properties

weak var delegate: DontBePopupDelegate?
Expand All @@ -25,10 +25,15 @@ final class DontBePopupView: UIView {
private let container: UIView = {
let view = UIView()
view.backgroundColor = .donWhite
view.layer.cornerRadius = 10
view.layer.cornerRadius = 10.adjusted
return view
}()

private let popupImageView: UIImageView = {
let popupImage = UIImageView()
return popupImage
}()

private let popupTitleLabel: UILabel = {
let label = UILabel()
label.textColor = .donBlack
Expand All @@ -42,13 +47,14 @@ final class DontBePopupView: UIView {
label.textColor = .donBlack
label.textAlignment = .center
label.font = UIFont.font(.body4)
label.numberOfLines = 0
return label
}()

private let buttonStackView: UIStackView = {
let stackView = UIStackView()
stackView.distribution = .fillEqually
stackView.spacing = 12
stackView.spacing = 12.adjusted
return stackView
}()

Expand All @@ -57,7 +63,7 @@ final class DontBePopupView: UIView {
button.setTitleColor(.donBlack, for: .normal)
button.titleLabel?.font = UIFont.font(.body3)
button.backgroundColor = .donGray3
button.layer.cornerRadius = 4
button.layer.cornerRadius = 4.adjusted
return button
}()

Expand All @@ -66,7 +72,7 @@ final class DontBePopupView: UIView {
button.setTitleColor(.donWhite, for: .normal)
button.titleLabel?.font = UIFont.font(.body3)
button.backgroundColor = .donBlack
button.layer.cornerRadius = 4
button.layer.cornerRadius = 4.adjusted
return button
}()

Expand All @@ -86,6 +92,23 @@ final class DontBePopupView: UIView {
setAddTarget()
}

init(popupImage: UIImage?, popupTitle: String, popupContent: String, leftButtonTitle: String, rightButtonTitle: String) {
super.init(frame: .zero)

popupTitleLabel.text = popupTitle // 팝업 타이틀
popupContentLabel.text = popupContent // 팝업 내용
cancleButton.setTitle(leftButtonTitle, for: .normal) // 팝업 왼쪽 버튼 타이틀
confirmButton.setTitle(rightButtonTitle, for: .normal) // 팝업 오른쪽 버튼 타이틀
if let image = popupImage {
popupImageView.image = image
}

setUI()
setHierarchy()
setLayout()
setAddTarget()
}

@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
Expand All @@ -109,6 +132,10 @@ extension DontBePopupView {
container.addSubviews(popupTitleLabel, popupContentLabel, buttonStackView)
}

if popupImageView.image != nil {
container.addSubviews(popupImageView, popupTitleLabel, popupContentLabel, buttonStackView)
}

buttonStackView.addArrangedSubviews(cancleButton, confirmButton)
}

Expand All @@ -131,25 +158,56 @@ extension DontBePopupView {
$0.height.equalTo(44.adjusted)
}
} else {
container.snp.makeConstraints {
$0.leading.trailing.equalToSuperview().inset(24.adjusted)
$0.centerY.equalToSuperview()
}

popupTitleLabel.snp.makeConstraints {
$0.top.equalToSuperview().inset(24.adjusted)
$0.leading.trailing.equalToSuperview().inset(18.adjusted)
}

popupContentLabel.snp.makeConstraints {
$0.top.equalTo(popupTitleLabel.snp.bottom).offset(12.adjusted)
$0.leading.trailing.equalToSuperview().inset(18.adjusted)
$0.bottom.equalTo(cancleButton.snp.top).offset(-26.adjusted)
}

buttonStackView.snp.makeConstraints {
$0.leading.trailing.bottom.equalToSuperview().inset(20.adjusted)
$0.height.equalTo(44.adjusted)
if popupImageView.image != nil {
container.snp.makeConstraints {
$0.leading.trailing.equalToSuperview().inset(24.adjusted)
$0.centerY.equalToSuperview()
}

popupImageView.snp.makeConstraints {
$0.top.equalToSuperview().inset(38.adjusted)
$0.size.equalTo(116.adjusted)
$0.centerX.equalToSuperview()
}

popupTitleLabel.snp.makeConstraints {
$0.top.equalTo(popupImageView.snp.bottom).offset(24.adjusted)
$0.leading.trailing.equalToSuperview().inset(18.adjusted)
}

popupContentLabel.snp.makeConstraints {
$0.top.equalTo(popupTitleLabel.snp.bottom).offset(12.adjusted)
$0.leading.trailing.equalToSuperview().inset(18.adjusted)
$0.bottom.equalTo(cancleButton.snp.top).offset(-26.adjusted)
}

buttonStackView.snp.makeConstraints {
$0.leading.trailing.bottom.equalToSuperview().inset(20.adjusted)
$0.height.equalTo(44.adjusted)
}
} else {

container.snp.makeConstraints {
$0.leading.trailing.equalToSuperview().inset(24.adjusted)
$0.centerY.equalToSuperview()
}

popupTitleLabel.snp.makeConstraints {
$0.top.equalToSuperview().inset(24.adjusted)
$0.leading.trailing.equalToSuperview().inset(18.adjusted)
}

popupContentLabel.snp.makeConstraints {
$0.top.equalTo(popupTitleLabel.snp.bottom).offset(12.adjusted)
$0.leading.trailing.equalToSuperview().inset(18.adjusted)
$0.bottom.equalTo(cancleButton.snp.top).offset(-26.adjusted)
}

buttonStackView.snp.makeConstraints {
$0.leading.trailing.bottom.equalToSuperview().inset(20.adjusted)
$0.height.equalTo(44.adjusted)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ final class HomeCollectionViewCell: UICollectionViewCell, UICollectionViewRegist

var KebabButtonAction: (() -> Void) = {}
var LikeButtonAction: (() -> Void) = {}
var TransparentButtonAction: (() -> Void) = {}
var isLiked: Bool = false

// MARK: - UI Components
Expand Down Expand Up @@ -169,16 +170,16 @@ extension HomeCollectionViewCell {
backgroundUIView.addSubviews(profileImageView,
nicknameLabel,
transparentLabel,
dotLabel,
dotLabel,
timeLabel,
kebabButton,
contentTextLabel,
contentTextLabel,
commentStackView,
likeStackView,
ghostButton,
verticalTextBarView)

likeStackView.addArrangedSubviews(likeButton,
likeStackView.addArrangedSubviews(likeButton,
likeNumLabel)
}

Expand Down Expand Up @@ -252,17 +253,22 @@ extension HomeCollectionViewCell {
}

func setAddTarget() {
kebabButton.addTarget(self, action: #selector(showButtons), for: .touchUpInside)
likeButton.addTarget(self, action: #selector(likeToggleButton), for: .touchUpInside)
}

kebabButton.addTarget(self, action: #selector(showButtons), for: .touchUpInside)
likeButton.addTarget(self, action: #selector(likeToggleButton), for: .touchUpInside)
ghostButton.addTarget(self, action: #selector(transparentShowPopupButton), for: .touchUpInside)
}

@objc
func showButtons() {
KebabButtonAction()
}
func showButtons() {
KebabButtonAction()
}

@objc
func likeToggleButton() {
LikeButtonAction()
}
func likeToggleButton() {
LikeButtonAction()
}
@objc
func transparentShowPopupButton() {
TransparentButtonAction()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ final class HomeViewController: UIViewController {
private lazy var homeCollectionView = HomeCollectionView().collectionView
private let uploadToastView = DontBeToastView()

private let transparentButtonPopupView = DontBePopupView(popupImage: UIImage(named: "transparentPopUp"), popupTitle: StringLiterals.Home.transparentPopupTitleLabel, popupContent: StringLiterals.Home.transparentPopupContentLabel, leftButtonTitle: StringLiterals.Home.transparentPopupLefteftButtonTitle, rightButtonTitle: StringLiterals.Home.transparentPopupRightButtonTitle)

// MARK: - Life Cycles

override func loadView() {
Expand Down Expand Up @@ -58,11 +60,13 @@ extension HomeViewController {
self.view.backgroundColor = UIColor.donGray1
self.navigationController?.navigationBar.isHidden = true
uploadToastView.alpha = 0
transparentButtonPopupView.alpha = 0
}

private func setHierarchy() {
view.addSubviews(homeCollectionView,
uploadToastView)
uploadToastView,
transparentButtonPopupView)
}

private func setLayout() {
Expand All @@ -77,11 +81,17 @@ extension HomeViewController {
$0.bottom.equalTo(tabBarHeight).inset(6.adjusted)
$0.height.equalTo(44)
}

transparentButtonPopupView.snp.makeConstraints {
$0.edges.equalToSuperview()
}

}

private func setDelegate() {
homeCollectionView.dataSource = self
homeCollectionView.delegate = self
transparentButtonPopupView.delegate = self
}

private func setNotification() {
Expand Down Expand Up @@ -154,6 +164,9 @@ extension HomeViewController: UICollectionViewDataSource, UICollectionViewDelega
cell.isLiked.toggle()
cell.likeButton.setImage(cell.isLiked ? ImageLiterals.Posting.btnFavoriteActive : ImageLiterals.Posting.btnFavoriteInActive, for: .normal)
}
cell.TransparentButtonAction = {
self.transparentButtonPopupView.alpha = 1
}
return cell
}

Expand All @@ -169,6 +182,16 @@ extension HomeViewController: UICollectionViewDataSource, UICollectionViewDelega
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {

return CGSize(width: UIScreen.main.bounds.width, height: 24.adjusted)

}
}

extension HomeViewController: DontBePopupDelegate {
func cancleButtonTapped() {
transparentButtonPopupView.alpha = 0
}

func confirmButtonTapped() {
transparentButtonPopupView.alpha = 0
// ✅ 투명도 주기 버튼 클릭 시 액션 추가
}
}

0 comments on commit a9a587c

Please sign in to comment.