Skip to content

Commit

Permalink
feat: Add BadgeStackView in BanchanCustomCell
Browse files Browse the repository at this point in the history
반찬 커스텀셀에 특가 배지 넣기위해 BadgeStaciView를 추가하였습니다.

issue: #12
  • Loading branch information
youngminshim-de committed Apr 23, 2021
1 parent 624cf29 commit 51bb2ee
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 47 deletions.
12 changes: 12 additions & 0 deletions iOS/SideDish/SideDish.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
04901C0F6905F46441D01E39 /* Pods_SideDish.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8C36659865215502B6A787B2 /* Pods_SideDish.framework */; };
0DA803948460ACB74095FF5D /* Pods_SideDish_SideDishUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0337C6601A2AF59C3D659E5B /* Pods_SideDish_SideDishUITests.framework */; };
5C69859173AA8099B0701A54 /* Pods_SideDishTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D7433C6120AE2C2B5B290532 /* Pods_SideDishTests.framework */; };
D4A2C9AC263273C10019AFB6 /* BadgeLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4A2C9AB263273C10019AFB6 /* BadgeLabel.swift */; };
D4BFBAD3262E989000D68297 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4BFBAD2262E989000D68297 /* AppDelegate.swift */; };
D4BFBAD5262E989000D68297 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4BFBAD4262E989000D68297 /* SceneDelegate.swift */; };
D4BFBAD7262E989000D68297 /* BanchanListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4BFBAD6262E989000D68297 /* BanchanListViewController.swift */; };
Expand Down Expand Up @@ -59,6 +60,7 @@
67FF510CB1C6C9C3BB8F2C5B /* Pods-SideDish.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SideDish.debug.xcconfig"; path = "Target Support Files/Pods-SideDish/Pods-SideDish.debug.xcconfig"; sourceTree = "<group>"; };
8C0DA2754EB6187A90B7076D /* Pods-SideDish-SideDishUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SideDish-SideDishUITests.release.xcconfig"; path = "Target Support Files/Pods-SideDish-SideDishUITests/Pods-SideDish-SideDishUITests.release.xcconfig"; sourceTree = "<group>"; };
8C36659865215502B6A787B2 /* Pods_SideDish.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SideDish.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D4A2C9AB263273C10019AFB6 /* BadgeLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BadgeLabel.swift; sourceTree = "<group>"; };
D4BFBACF262E989000D68297 /* SideDish.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SideDish.app; sourceTree = BUILT_PRODUCTS_DIR; };
D4BFBAD2262E989000D68297 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
D4BFBAD4262E989000D68297 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -142,6 +144,14 @@
name = Frameworks;
sourceTree = "<group>";
};
D4A2C9AA263273A60019AFB6 /* Utills */ = {
isa = PBXGroup;
children = (
D4A2C9AB263273C10019AFB6 /* BadgeLabel.swift */,
);
path = Utills;
sourceTree = "<group>";
};
D4BFBAC6262E989000D68297 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -198,6 +208,7 @@
D4BFBB19262EA74E00D68297 /* Presentaion */ = {
isa = PBXGroup;
children = (
D4A2C9AA263273A60019AFB6 /* Utills */,
D4BFBB1F262EA7AC00D68297 /* DetailBanchan */,
D4BFBB1E262EA7A100D68297 /* BanchanList */,
);
Expand Down Expand Up @@ -583,6 +594,7 @@
D4BFBB35262EB89800D68297 /* BanchanCustomCell.swift in Sources */,
D4BFBB2A262EA93700D68297 /* Banchan.swift in Sources */,
FFEF71092631128900189376 /* FetchImageUseCase.swift in Sources */,
D4A2C9AC263273C10019AFB6 /* BadgeLabel.swift in Sources */,
FFEF7123263119C500189376 /* BanchanListViewModel.swift in Sources */,
D4BFBB3C262EC8DB00D68297 /* BanchanCustomCellHeader.swift in Sources */,
);
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class BanchanCustomCell: UICollectionViewCell {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var descriptionLabel: UILabel!
@IBOutlet weak var netPriceLabel: UILabel!
@IBOutlet weak var salePriceLabel: UILabel!
@IBOutlet weak var priceTypeLabel: UILabel!
@IBOutlet weak var sPriceLabel: UILabel!
@IBOutlet weak var nPriceLabel: UILabel!
@IBOutlet weak var badgeStackView: UIStackView!

static let identifer = "BanchanCustomCell"

Expand All @@ -27,9 +27,9 @@ class BanchanCustomCell: UICollectionViewCell {
loadImages(imgURL: banchan?.image ?? "")
titleLabel.text = banchan?.title
descriptionLabel.text = banchan?.description
netPriceLabel.text = "1000"
salePriceLabel.text = "2000"
priceTypeLabel.text = "3000"
setNPrice(text: banchan?.nPrice)
sPriceLabel.text = banchan?.sPrice
setBadges(badges: banchan?.badge)
}
}

Expand All @@ -46,4 +46,32 @@ class BanchanCustomCell: UICollectionViewCell {
}
}
}

private func setNPrice(text: String?) {
guard let text = text else {
nPriceLabel.isHidden = true
return
}
let strikeThroughAttributeStyle = [NSAttributedString.Key.strikethroughStyle: NSNumber(value: NSUnderlineStyle.single.rawValue)]

nPriceLabel.attributedText = NSAttributedString(string: text+"", attributes: strikeThroughAttributeStyle)
}

private func setBadges(badges: [String]?) {
badgeStackView.arrangedSubviews.forEach {
$0.removeFromSuperview()
}

guard let badges = badges else {
badgeStackView.isHidden = true
return
}

badges.forEach { (badge) in
let badgeLabel = BadgeLabel()
badgeLabel.configure(text: badge)
badgeStackView.addArrangedSubview(badgeLabel)
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="btw-tC-wyy">
<rect key="frame" x="138" y="11" width="205" height="29"/>
<rect key="frame" x="138" y="11" width="205" height="32"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="23" id="t7w-MD-aLz"/>
</constraints>
Expand All @@ -37,63 +37,43 @@
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ik5-kh-p0g">
<rect key="frame" x="138" y="44" width="205" height="17"/>
<rect key="frame" x="138" y="47" width="205" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" systemColor="systemGray3Color"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="jxS-Ry-Pui">
<rect key="frame" x="138" y="69" width="37.5" height="17"/>
<rect key="frame" x="138" y="72" width="37.5" height="17"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="14"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="PPm-N9-df2">
<rect key="frame" x="179.5" y="69" width="35.5" height="17"/>
<rect key="frame" x="179.5" y="72" width="35.5" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" systemColor="systemGray4Color"/>
<nil key="highlightedColor"/>
</label>
<view clipsSubviews="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="fpU-6X-kg6">
<rect key="frame" x="138" y="94" width="72" height="25"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="EQE-BG-bRq">
<rect key="frame" x="8" y="4" width="56" height="17"/>
<constraints>
<constraint firstAttribute="height" constant="17" id="TJ4-MA-qpS"/>
<constraint firstAttribute="width" constant="56" id="uua-t8-0Lg"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" systemColor="systemGreenColor"/>
<stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" spacing="4" translatesAutoresizingMaskIntoConstraints="NO" id="dN3-p0-I7M">
<rect key="frame" x="138" y="97" width="113" height="25"/>
<constraints>
<constraint firstItem="EQE-BG-bRq" firstAttribute="leading" secondItem="fpU-6X-kg6" secondAttribute="leading" constant="8" id="5TL-q3-mXU"/>
<constraint firstAttribute="trailing" secondItem="EQE-BG-bRq" secondAttribute="trailing" constant="8" id="9q0-Zw-S4L"/>
<constraint firstItem="EQE-BG-bRq" firstAttribute="top" secondItem="fpU-6X-kg6" secondAttribute="top" constant="4" id="cgp-Cq-gTC"/>
<constraint firstAttribute="bottom" secondItem="EQE-BG-bRq" secondAttribute="bottom" constant="4" id="msx-zB-FTh"/>
<constraint firstAttribute="width" relation="lessThanOrEqual" constant="205" id="J8g-WW-KFr"/>
<constraint firstAttribute="height" constant="25" id="YOU-b5-FHH"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" priority="750" constant="20" id="fiQ-Yy-BeV"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="boolean" keyPath="layer.masksToBounds" value="YES"/>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="15"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
</stackView>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="dN3-p0-I7M" firstAttribute="leading" secondItem="g5T-aK-miE" secondAttribute="trailing" constant="8" id="3Y9-41-blU"/>
<constraint firstItem="btw-tC-wyy" firstAttribute="top" secondItem="xjh-Lo-rq1" secondAttribute="top" constant="11" id="3yj-m5-pzJ"/>
<constraint firstAttribute="bottom" secondItem="dN3-p0-I7M" secondAttribute="bottom" constant="8" id="5f4-Il-X53"/>
<constraint firstItem="jxS-Ry-Pui" firstAttribute="leading" secondItem="g5T-aK-miE" secondAttribute="trailing" constant="8" id="I98-Yg-wGw"/>
<constraint firstItem="btw-tC-wyy" firstAttribute="leading" secondItem="g5T-aK-miE" secondAttribute="trailing" constant="8" id="K5s-eE-gUq"/>
<constraint firstItem="g5T-aK-miE" firstAttribute="leading" secondItem="xjh-Lo-rq1" secondAttribute="leading" id="KoG-gP-Pyr"/>
<constraint firstItem="dN3-p0-I7M" firstAttribute="top" secondItem="jxS-Ry-Pui" secondAttribute="bottom" constant="8" id="LBl-38-iB4"/>
<constraint firstItem="g5T-aK-miE" firstAttribute="top" secondItem="xjh-Lo-rq1" secondAttribute="top" id="R2z-Pf-CL5"/>
<constraint firstAttribute="bottom" secondItem="fpU-6X-kg6" secondAttribute="bottom" constant="11" id="Sjn-rr-xXz"/>
<constraint firstItem="PPm-N9-df2" firstAttribute="top" secondItem="ik5-kh-p0g" secondAttribute="bottom" constant="8" id="VvU-lU-aOd"/>
<constraint firstItem="fpU-6X-kg6" firstAttribute="top" secondItem="PPm-N9-df2" secondAttribute="bottom" constant="8" id="XNe-eh-3XH"/>
<constraint firstItem="fpU-6X-kg6" firstAttribute="leading" secondItem="g5T-aK-miE" secondAttribute="trailing" constant="8" id="jl7-OM-uZB"/>
<constraint firstItem="ik5-kh-p0g" firstAttribute="leading" secondItem="g5T-aK-miE" secondAttribute="trailing" constant="8" id="mca-e5-zEQ"/>
<constraint firstAttribute="trailing" secondItem="ik5-kh-p0g" secondAttribute="trailing" id="pD6-jZ-iZR"/>
<constraint firstItem="jxS-Ry-Pui" firstAttribute="top" secondItem="ik5-kh-p0g" secondAttribute="bottom" constant="8" id="q2x-lg-Bgf"/>
Expand All @@ -112,11 +92,11 @@
<constraint firstItem="ZTg-uK-7eu" firstAttribute="bottom" secondItem="xjh-Lo-rq1" secondAttribute="bottom" id="wmR-MA-Dh6"/>
</constraints>
<connections>
<outlet property="badgeStackView" destination="dN3-p0-I7M" id="VjC-aB-C3A"/>
<outlet property="descriptionLabel" destination="ik5-kh-p0g" id="eXl-Mk-lza"/>
<outlet property="imageView" destination="g5T-aK-miE" id="yXe-Xv-Wqs"/>
<outlet property="netPriceLabel" destination="jxS-Ry-Pui" id="COP-iC-kIV"/>
<outlet property="priceTypeLabel" destination="EQE-BG-bRq" id="qOj-KZ-rTD"/>
<outlet property="salePriceLabel" destination="PPm-N9-df2" id="CUu-3U-hbQ"/>
<outlet property="nPriceLabel" destination="PPm-N9-df2" id="Uab-GM-eOe"/>
<outlet property="sPriceLabel" destination="jxS-Ry-Pui" id="xKc-Wv-h2a"/>
<outlet property="titleLabel" destination="btw-tC-wyy" id="VZl-7D-ovF"/>
</connections>
<point key="canvasLocation" x="-16.666666666666668" y="95.758928571428569"/>
Expand All @@ -132,8 +112,5 @@
<systemColor name="systemGray4Color">
<color red="0.81960784313725488" green="0.81960784313725488" blue="0.83921568627450982" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemGreenColor">
<color red="0.20392156862745098" green="0.7803921568627451" blue="0.34901960784313724" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources>
</document>
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BanchanListViewController: UIViewController {
case .finished:
break
}
}, receiveValue: { (value) in
}, receiveValue: { [unowned self] _ in
self.applySnapshot()
})
.store(in: &subscriptions)
Expand Down Expand Up @@ -87,7 +87,8 @@ extension BanchanListViewController {
// MARK: - Delegate
extension BanchanListViewController: UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 343, height: 130)
let cellSize = CGSize(width: 343, height: 130)
return cellSize
}
}

47 changes: 47 additions & 0 deletions iOS/SideDish/SideDish/Presentaion/Utills/BadgeLabel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// BadgeLabel.swift
// SideDish
//
// Created by 지북 on 2021/04/22.
//

import UIKit

class BadgeLabel: UILabel {

private let topInset: CGFloat = 4.0
private let bottomInset: CGFloat = 4.0
private let leftInset: CGFloat = 8.0
private let rightInset: CGFloat = 8.0

let badgeColors: [String:UIColor] = ["이벤트특가": UIColor(displayP3Red: 130/255, green: 211/255, blue: 45/255, alpha: 1), "론칭특가": UIColor(displayP3Red: 134/255, green: 198/255, blue: 255/255, alpha: 1)]

override init(frame: CGRect) {
super.init(frame: frame)
}

required init?(coder: NSCoder) {
super.init(coder: coder)
}

func configure(text badgeText: String) {
translatesAutoresizingMaskIntoConstraints = false
font = UIFont.systemFont(ofSize: 12, weight: .regular)
textColor = .white
backgroundColor = badgeColors[badgeText]
text = badgeText
clipsToBounds = true
layer.cornerRadius = 5
}

override func drawText(in rect: CGRect) {
let insets = UIEdgeInsets(top: topInset, left: leftInset, bottom: bottomInset, right: rightInset)
super.drawText(in: rect.inset(by: insets))
}

override var intrinsicContentSize: CGSize {
let size = super.intrinsicContentSize
return CGSize(width: size.width + leftInset + rightInset,
height: size.height + topInset + bottomInset)
}
}

0 comments on commit 51bb2ee

Please sign in to comment.