Skip to content

Commit 125fa3a

Browse files
Hamza GhazouaniHamzaGhazouani
authored andcommitted
Add more properties for customization: titleFont, subtitleFont and actionTitleFont
1 parent 7b46c62 commit 125fa3a

File tree

11 files changed

+82
-63
lines changed

11 files changed

+82
-63
lines changed

Example/HGPlaceholders.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@
567567
INFOPLIST_FILE = "$(SRCROOT)/HGPlaceholders/Resources/Info.plist";
568568
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
569569
MODULE_NAME = ExampleApp;
570-
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
570+
PRODUCT_BUNDLE_IDENTIFIER = "com.onmobile.HGPlaceholders-Example";
571571
PRODUCT_NAME = "$(TARGET_NAME)";
572572
SWIFT_VERSION = 3.0;
573573
};
@@ -582,7 +582,7 @@
582582
INFOPLIST_FILE = "$(SRCROOT)/HGPlaceholders/Resources/Info.plist";
583583
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
584584
MODULE_NAME = ExampleApp;
585-
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
585+
PRODUCT_BUNDLE_IDENTIFIER = "com.onmobile.HGPlaceholders-Example";
586586
PRODUCT_NAME = "$(TARGET_NAME)";
587587
SWIFT_VERSION = 3.0;
588588
};

Example/HGPlaceholders/PlaceholdersProvider.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ extension PlaceholdersProvider {
1717
commonStyle.titleColor = .black
1818
commonStyle.isAnimated = false
1919

20+
commonStyle.titleFont = UIFont(name: "AvenirNextCondensed-HeavyItalic", size: 19)!
21+
commonStyle.subtitleFont = UIFont(name: "AvenirNextCondensed-Italic", size: 19)!
22+
commonStyle.actionTitleFont = UIFont(name: "AvenirNextCondensed-Heavy", size: 19)!
23+
2024
var loadingStyle = commonStyle
2125
loadingStyle.actionBackgroundColor = .clear
2226
loadingStyle.actionTitleColor = .gray

HGPlaceholders/Classes/Cells/PlaceholderCollectionViewCell.xib

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<dependencies>
77
<deployment identifier="iOS"/>
88
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
9+
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
910
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
1011
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1112
</dependencies>
@@ -24,24 +25,22 @@
2425
<subviews>
2526
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="253" image="halloween-loading" translatesAutoresizingMaskIntoConstraints="NO" id="c7U-EM-TGb">
2627
<rect key="frame" x="76.5" y="0.0" width="120" height="128"/>
28+
<constraints>
29+
<constraint firstAttribute="width" priority="100" id="Zn5-rH-3Dz"/>
30+
<constraint firstAttribute="width" secondItem="c7U-EM-TGb" secondAttribute="height" priority="100" id="sgm-6z-Mtd"/>
31+
</constraints>
2732
</imageView>
2833
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="752" text="Title" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="cIN-cg-xzD">
2934
<rect key="frame" x="0.0" y="148" width="273" height="23"/>
30-
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="19"/>
35+
<fontDescription key="fontDescription" type="boldSystem" pointSize="19"/>
3136
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
3237
<nil key="highlightedColor"/>
33-
<variation key="heightClass=compact-widthClass=compact">
34-
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="15"/>
35-
</variation>
3638
</label>
3739
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="252" verticalCompressionResistancePriority="751" text="Subtitle" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="B15-GK-QdK">
3840
<rect key="frame" x="0.0" y="176" width="273" height="17"/>
3941
<fontDescription key="fontDescription" type="system" pointSize="14"/>
4042
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
4143
<nil key="highlightedColor"/>
42-
<variation key="heightClass=compact-widthClass=compact">
43-
<fontDescription key="fontDescription" type="system" pointSize="12"/>
44-
</variation>
4544
</label>
4645
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="999" verticalCompressionResistancePriority="999" hidesWhenStopped="YES" style="white" translatesAutoresizingMaskIntoConstraints="NO" id="JMg-2S-oJM">
4746
<rect key="frame" x="126.5" y="213" width="20" height="20"/>
@@ -90,7 +89,6 @@
9089
</button>
9190
</subviews>
9291
</view>
93-
<color key="backgroundColor" red="0.047058823530000002" green="0.63137254899999995" blue="1" alpha="1" colorSpace="calibratedRGB"/>
9492
<constraints>
9593
<constraint firstItem="MXU-dt-vhe" firstAttribute="leading" secondItem="gTV-IL-0wX" secondAttribute="leadingMargin" id="3rF-DX-Ipu"/>
9694
<constraint firstAttribute="bottom" secondItem="2sn-za-oDj" secondAttribute="bottom" constant="20" id="IuB-zj-UQA"/>

HGPlaceholders/Classes/Cells/PlaceholderTableViewCell.xib

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<dependencies>
77
<deployment identifier="iOS"/>
88
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
9+
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
910
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
1011
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1112
</dependencies>
@@ -19,32 +20,31 @@
1920
<rect key="frame" x="44" y="0.0" width="232" height="376.66666666666669"/>
2021
<autoresizingMask key="autoresizingMask"/>
2122
<subviews>
22-
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="db1-Fl-G6D">
23-
<rect key="frame" x="8" y="86.666666666666686" width="304" height="205"/>
23+
<view contentMode="scaleToFill" verticalHuggingPriority="1000" verticalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="db1-Fl-G6D">
24+
<rect key="frame" x="8" y="82" width="304" height="213"/>
2425
<subviews>
2526
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" image="halloween-loading" translatesAutoresizingMaskIntoConstraints="NO" id="oEI-sb-ulS">
26-
<rect key="frame" x="92" y="0.0" width="120" height="127.99999999999999"/>
27+
<rect key="frame" x="92" y="0.0" width="120" height="128"/>
28+
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
29+
<constraints>
30+
<constraint firstAttribute="width" secondItem="oEI-sb-ulS" secondAttribute="height" multiplier="1:1" priority="100" id="PV3-EQ-CV6"/>
31+
<constraint firstAttribute="width" priority="100" id="UcD-l1-ZTX"/>
32+
</constraints>
2733
</imageView>
2834
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="752" text="Title" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="JBE-d5-jAM">
29-
<rect key="frame" x="0.0" y="138" width="304" height="18"/>
35+
<rect key="frame" x="0.0" y="138" width="304" height="23"/>
3036
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="19"/>
3137
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
3238
<nil key="highlightedColor"/>
33-
<variation key="heightClass=compact-widthClass=compact">
34-
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="15"/>
35-
</variation>
3639
</label>
3740
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="751" text="Subtitle" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="Efm-pp-P5W">
38-
<rect key="frame" x="0.0" y="161" width="304" height="14.000000000000028"/>
41+
<rect key="frame" x="0.0" y="166" width="304" height="17"/>
3942
<fontDescription key="fontDescription" type="system" pointSize="14"/>
4043
<color key="textColor" white="0.33333333329999998" alpha="1" colorSpace="calibratedWhite"/>
4144
<nil key="highlightedColor"/>
42-
<variation key="heightClass=compact-widthClass=compact">
43-
<fontDescription key="fontDescription" type="system" pointSize="12"/>
44-
</variation>
4545
</label>
4646
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="999" verticalCompressionResistancePriority="999" hidesWhenStopped="YES" style="white" translatesAutoresizingMaskIntoConstraints="NO" id="7OP-IO-NHg">
47-
<rect key="frame" x="142" y="185" width="20" height="20"/>
47+
<rect key="frame" x="142" y="193" width="20" height="20"/>
4848
</activityIndicatorView>
4949
</subviews>
5050
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>

HGPlaceholders/Classes/Placeholder/Placeholder.swift

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,28 @@ public struct Placeholder {
2424
public let key: PlaceholderKey
2525

2626

27-
/// Create and return a Placeholder object with the specified identifier, data, style, and key
27+
/// Create a placeholder by using the data and style objects
2828
///
2929
/// - Parameters:
30-
/// - cellIdentifier: the identifier of the cell to use as a placeholder, set it only if you want to add a custom placeholder
31-
/// - data: the data of the placeholder s
30+
/// - data: the data of the placeholder
3231
/// - style: the style of the placeholder
3332
/// - key: the unique key of the placeholder
34-
public init(cellIdentifier: String? = nil, data: PlaceholderData? = nil, style: PlaceholderStyle? = nil, key: PlaceholderKey) {
33+
public init(data: PlaceholderData, style: PlaceholderStyle, key: PlaceholderKey) {
3534
self.key = key
36-
self.cellIdentifier = cellIdentifier
3735
self.style = style
3836
self.data = data
37+
38+
self.cellIdentifier = nil
39+
}
40+
41+
42+
/// Create a placeholder by using custom xib file
43+
///
44+
/// - Parameters:
45+
/// - cellIdentifier: The identifier of the cell to use as a placeholder
46+
/// - key: the unique key of the placeholder
47+
public init(cellIdentifier: String, key: PlaceholderKey) {
48+
self.key = key
49+
self.cellIdentifier = cellIdentifier
3950
}
4051
}

HGPlaceholders/Classes/Placeholder/PlaceholderStyle.swift

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,37 @@ public struct PlaceholderStyle {
1414

1515
// MARK: properties
1616

17-
/// The color of the placeholder title
18-
public var titleColor: UIColor?
19-
/// The color of the placeholder subtitle
20-
public var subtitleColor: UIColor?
21-
22-
/// The color of the action button title of the placeholder
23-
public var actionTitleColor: UIColor?
24-
/// The color of the action button background of the placeholder
17+
/// The color of the placeholder title, the default value is darkText
18+
public var titleColor: UIColor = .darkText
19+
/// The font of the placeholder title, the default value is boldSystemFont 19
20+
public var titleFont = UIFont.boldSystemFont(ofSize: 19)
21+
22+
/// The color of the placeholder subtitle, the default value is gray
23+
public var subtitleColor: UIColor = .gray
24+
/// The font of the placeholder subtitle, the default value is systemFont 14
25+
public var subtitleFont = UIFont.systemFont(ofSize: 14)
26+
27+
/// The color of the action button title of the placeholder, the default value is white
28+
public var actionTitleColor: UIColor = .white
29+
/// The font of the placeholder subtitle, the default value is boldSystemFont 17
30+
public var actionTitleFont = UIFont.boldSystemFont(ofSize: 17)
31+
32+
/// The color of the action button background of the placeholder, the default value is the tint color
2533
public var actionBackgroundColor: UIColor?
2634

27-
/// The color of activity indicator view of the placeholder
28-
public var activityIndicatorColor: UIColor?
35+
/// The color of activity indicator view of the placeholder, the default value is light gray
36+
public var activityIndicatorColor = UIColor.lightGray
2937

30-
/// The background color of the placeholder
31-
public var backgroundColor: UIColor?
38+
/// The background color of the placeholder, the default value is clear
39+
public var backgroundColor = UIColor.clear
3240

3341
/// Should display the placeholder with animation or not
3442
public var isAnimated = true
3543

36-
/// Should display the tableViewHeader or not
44+
/// Should display the tableViewHeader or not, the default value is false
3745
public var shouldShowTableViewHeader = false
3846

39-
/// Should display the tableViewFooter or not
47+
/// Should display the tableViewFooter or not, the default value is false
4048
public var shouldShowTableViewFooter = false
4149

4250
// MARK: init methods

HGPlaceholders/Classes/PlaceholdersProvider/PlaceholderDataSourceDelegate.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class PlaceholderDataSourceDelegate: NSObject {
3636
/// - tintColor: the tint color to apply
3737
func fill(cell: CellPlaceholding, to placeholder: Placeholder, tintColor: UIColor?) {
3838

39+
/** if the the placeholder created by xib and data/style are nil, we should keep the xib data/style **/
40+
3941
// apply style
4042
if let style = placeholder.style {
4143
cell.apply(style: style, tintColor: tintColor)

HGPlaceholders/Classes/Protocols/CellPlaceholding.swift

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protocol CellPlaceholding {
3131
/// Sets in the cell the placeholder texts, image, ...
3232
///
3333
/// - Parameter data: the data of the cell (texts, images, etc)
34-
func apply(data: PlaceholderData)
34+
func apply(data: PlaceholderData?)
3535
}
3636

3737

@@ -45,38 +45,35 @@ extension CellPlaceholding {
4545
/// - style: the style to apply
4646
/// - tintColor: the tint color, is used for some items when the style color is nil
4747
internal func apply(style: PlaceholderStyle, tintColor: UIColor?) {
48-
cellView.backgroundColor = style.backgroundColor ?? .clear
48+
cellView.backgroundColor = style.backgroundColor
4949

5050
let buttonBackgroundColor = style.actionBackgroundColor ?? tintColor
5151
actionButton?.backgroundColor = buttonBackgroundColor
5252

53-
let actionColor = style.actionTitleColor ?? .white
53+
let actionColor = style.actionTitleColor
5454
actionButton?.setTitleColor(actionColor, for: .normal)
55+
actionButton?.titleLabel?.font = style.actionTitleFont
5556

56-
activityIndicator?.color = style.activityIndicatorColor ?? .lightGray
57-
58-
titleLabel?.textColor = style.titleColor ?? .darkText
59-
subtitleLabel?.textColor = style.subtitleColor ?? .gray
57+
activityIndicator?.color = style.activityIndicatorColor
6058

59+
titleLabel?.textColor = style.titleColor
60+
titleLabel?.font = style.titleFont
6161

62+
subtitleLabel?.textColor = style.subtitleColor
63+
subtitleLabel?.font = style.subtitleFont
6264
}
6365

6466
/// Sets in the cell the placeholder texts, image, ...
6567
///
6668
/// - Parameter data: the data of the cell (texts, images, etc)
67-
internal func apply(data: PlaceholderData) {
68-
actionButton?.setTitle(data.action, for: .normal)
69-
actionButton?.isHidden = (data.action == nil)
70-
71-
titleLabel?.text = data.title
72-
titleLabel?.isHidden = (data.title == nil)
73-
74-
subtitleLabel?.text = data.subtitle
75-
subtitleLabel?.isHidden = (data.title == nil)
69+
internal func apply(data: PlaceholderData?) {
70+
actionButton?.setTitle(data?.action, for: .normal)
71+
actionButton?.isHidden = (data?.action == nil)
7672

77-
placeholderImageView?.image = data.image
78-
placeholderImageView?.isHidden = (data.image == nil)
73+
titleLabel?.text = data?.title
74+
subtitleLabel?.text = data?.subtitle
75+
placeholderImageView?.image = data?.image
7976

80-
data.showsLoading == true ? activityIndicator?.startAnimating() : activityIndicator?.stopAnimating()
77+
data?.showsLoading == true ? activityIndicator?.startAnimating() : activityIndicator?.stopAnimating()
8178
}
8279
}

HGPlaceholders/Classes/Views/CollectionView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ open class CollectionView: UICollectionView {
109109

110110
- returns: Returns an initialized collectionView object, or nil if the object could not be successfully initialized.
111111
*/
112-
public override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
112+
override public init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
113113
super.init(frame: frame, collectionViewLayout: layout)
114114

115115
setup()

HGPlaceholders/Classes/Views/TableView+Switcher.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,4 @@ extension TableView: PlaceholdersSwitcher {
5454
public func showDefault() {
5555
self.switchTo(dataSource: defaultDataSource, delegate: defaultDelegate)
5656
}
57-
5857
}

0 commit comments

Comments
 (0)