Skip to content

Commit 732ade4

Browse files
committed
Added textSize property and left top right bottom tag padding
1 parent 34f0fc3 commit 732ade4

File tree

9 files changed

+76
-37
lines changed

9 files changed

+76
-37
lines changed

Example/Hashtags.xcodeproj/project.pbxproj

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@
229229
};
230230
607FACE41AFB9204008FA782 = {
231231
CreatedOnToolsVersion = 6.3.1;
232-
DevelopmentTeam = DBEPTECPFM;
233232
LastSwiftMigration = 0900;
233+
ProvisioningStyle = Manual;
234234
TestTargetID = 607FACCF1AFB9204008FA782;
235235
};
236236
};
@@ -531,6 +531,7 @@
531531
baseConfigurationReference = 917CC9E18418EF1069980A51 /* Pods-Hashtags_Example.debug.xcconfig */;
532532
buildSettings = {
533533
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
534+
CODE_SIGN_IDENTITY = "iPhone Developer";
534535
CODE_SIGN_STYLE = Manual;
535536
DEVELOPMENT_TEAM = "";
536537
INFOPLIST_FILE = Hashtags/Info.plist;
@@ -550,6 +551,7 @@
550551
baseConfigurationReference = 6C817035909AC2664FE21E52 /* Pods-Hashtags_Example.release.xcconfig */;
551552
buildSettings = {
552553
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
554+
CODE_SIGN_IDENTITY = "iPhone Developer";
553555
CODE_SIGN_STYLE = Manual;
554556
DEVELOPMENT_TEAM = "";
555557
INFOPLIST_FILE = Hashtags/Info.plist;
@@ -568,7 +570,8 @@
568570
isa = XCBuildConfiguration;
569571
baseConfigurationReference = CD21704F302ED2D69FFEDF25 /* Pods-Hashtags_Tests.debug.xcconfig */;
570572
buildSettings = {
571-
DEVELOPMENT_TEAM = DBEPTECPFM;
573+
CODE_SIGN_STYLE = Manual;
574+
DEVELOPMENT_TEAM = "";
572575
FRAMEWORK_SEARCH_PATHS = (
573576
"$(SDKROOT)/Developer/Library/Frameworks",
574577
"$(inherited)",
@@ -581,6 +584,7 @@
581584
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
582585
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
583586
PRODUCT_NAME = "$(TARGET_NAME)";
587+
PROVISIONING_PROFILE_SPECIFIER = "";
584588
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
585589
SWIFT_VERSION = 4.0;
586590
};
@@ -590,7 +594,8 @@
590594
isa = XCBuildConfiguration;
591595
baseConfigurationReference = 0C873CC375B45B25507BC693 /* Pods-Hashtags_Tests.release.xcconfig */;
592596
buildSettings = {
593-
DEVELOPMENT_TEAM = DBEPTECPFM;
597+
CODE_SIGN_STYLE = Manual;
598+
DEVELOPMENT_TEAM = "";
594599
FRAMEWORK_SEARCH_PATHS = (
595600
"$(SDKROOT)/Developer/Library/Frameworks",
596601
"$(inherited)",
@@ -599,6 +604,7 @@
599604
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
600605
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
601606
PRODUCT_NAME = "$(TARGET_NAME)";
607+
PROVISIONING_PROFILE_SPECIFIER = "";
602608
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
603609
SWIFT_VERSION = 4.0;
604610
};

Example/Hashtags/Base.lproj/Main.storyboard

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="CHW-cI-DMX">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14269.12" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="CHW-cI-DMX">
33
<device id="retina4_7" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
66
<dependencies>
7-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14252.5"/>
89
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
910
</dependencies>
1011
<scenes>
@@ -37,7 +38,7 @@
3738
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
3839
<subviews>
3940
<stackView opaque="NO" contentMode="scaleToFill" spacing="30" translatesAutoresizingMaskIntoConstraints="NO" id="N5r-yW-KWS">
40-
<rect key="frame" x="77" y="318" width="221" height="30"/>
41+
<rect key="frame" x="77" y="318.5" width="221" height="30"/>
4142
<subviews>
4243
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="QLS-ho-fYv">
4344
<rect key="frame" x="0.0" y="0.0" width="111" height="30"/>
@@ -99,7 +100,7 @@
99100
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
100101
<subviews>
101102
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Hashtags, using Storyboard" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="IHt-4b-UPZ" userLabel="Title">
102-
<rect key="frame" x="48" y="114" width="280" height="30"/>
103+
<rect key="frame" x="47.5" y="114" width="280" height="30"/>
103104
<fontDescription key="fontDescription" type="system" weight="thin" pointSize="25"/>
104105
<color key="textColor" red="0.99999600649999998" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
105106
<nil key="highlightedColor"/>

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Hashtags.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'Hashtags'
11-
s.version = '0.1.0'
11+
s.version = '0.1.1'
1212
s.summary = 'A swift library for displaying hashtags'
1313
s.swift_version = '4.0'
1414
s.description = "Display a list of hashtags dynamically."

Hashtags/Classes/HashtagCollectionViewCell.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ open class HashtagCollectionViewCell: UICollectionViewCell {
2020

2121
lazy var wordLabel : UILabel = {
2222
let lbl = UILabel()
23-
lbl.font = UIFont.systemFont(ofSize: 14)
2423
lbl.textColor = UIColor.white
24+
lbl.textAlignment = .center
25+
lbl.translatesAutoresizingMaskIntoConstraints = false
2526
return lbl
2627
}()
2728

@@ -39,12 +40,9 @@ open class HashtagCollectionViewCell: UICollectionViewCell {
3940

4041
open func setup() {
4142
self.clipsToBounds = true
42-
self.wordLabel.textAlignment = .center
4343

4444
self.addSubview(wordLabel)
4545

46-
self.wordLabel.translatesAutoresizingMaskIntoConstraints = false
47-
4846
// Padding left
4947
self.paddingLeftConstraint = self.wordLabel.leadingAnchor.constraint(equalTo: self.leadingAnchor)
5048
self.paddingLeftConstraint!.isActive = true
@@ -59,6 +57,11 @@ open class HashtagCollectionViewCell: UICollectionViewCell {
5957
self.paddingRightConstraint!.isActive = true
6058
}
6159

60+
open override func prepareForInterfaceBuilder() {
61+
self.wordLabel.text = ""
62+
super.prepareForInterfaceBuilder()
63+
}
64+
6265
open func configureWithTag(tag: HashTag, configuration: HashtagConfiguration) {
6366
self.hashtag = tag
6467
wordLabel.text = tag.text
@@ -68,8 +71,10 @@ open class HashtagCollectionViewCell: UICollectionViewCell {
6871
self.paddingBottomConstraint!.constant = -1 * configuration.paddingBottom
6972
self.paddingRightConstraint!.constant = -1 * configuration.paddingRight
7073

74+
self.layer.cornerRadius = configuration.cornerRadius
7175
self.backgroundColor = configuration.backgroundColor
76+
7277
self.wordLabel.textColor = configuration.textColor
73-
self.layer.cornerRadius = configuration.cornerRadius
78+
self.wordLabel.font = UIFont.systemFont(ofSize: configuration.textSize)
7479
}
7580
}

Hashtags/Classes/HashtagConfiguration.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ open class HashtagConfiguration {
1515
var removeButtonSize: CGFloat = 0.0
1616
var removeButtonSpacing: CGFloat = 0.0
1717
var cornerRadius: CGFloat = 0.0
18+
var textSize: CGFloat = 0.0
1819
var textColor = UIColor()
1920
var backgroundColor = UIColor()
2021
}

Hashtags/Classes/HashtagView.swift

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,28 @@ open class HashtagView: UIView {
7575
// MARK: Hashtag cell padding
7676

7777
@IBInspectable
78-
open var tagPadding: CGFloat = 5.0 {
78+
open var tagPaddingLeft: CGFloat = 5.0 {
79+
didSet {
80+
self.collectionView.reloadData()
81+
}
82+
}
83+
84+
@IBInspectable
85+
open var tagPaddingRight: CGFloat = 5.0 {
86+
didSet {
87+
self.collectionView.reloadData()
88+
}
89+
}
90+
91+
@IBInspectable
92+
open var tagPaddingTop: CGFloat = 5.0 {
93+
didSet {
94+
self.collectionView.reloadData()
95+
}
96+
}
97+
98+
@IBInspectable
99+
open var tagPaddingBottom: CGFloat = 5.0 {
79100
didSet {
80101
self.collectionView.reloadData()
81102
}
@@ -88,6 +109,13 @@ open class HashtagView: UIView {
88109
}
89110
}
90111

112+
@IBInspectable
113+
open var textSize: CGFloat = 14.0 {
114+
didSet {
115+
self.collectionView.reloadData()
116+
}
117+
}
118+
91119
@IBInspectable
92120
open var tagBackgroundColor: UIColor = .lightGray {
93121
didSet {
@@ -179,14 +207,15 @@ open class HashtagView: UIView {
179207

180208
let configuration = HashtagConfiguration()
181209

182-
configuration.paddingLeft = self.tagPadding
183-
configuration.paddingRight = self.tagPadding
184-
configuration.paddingTop = self.tagPadding
185-
configuration.paddingBottom = self.tagPadding
210+
configuration.paddingLeft = self.tagPaddingLeft
211+
configuration.paddingRight = self.tagPaddingRight
212+
configuration.paddingTop = self.tagPaddingTop
213+
configuration.paddingBottom = self.tagPaddingBottom
186214
configuration.removeButtonSize = self.removeButtonSize
187215
configuration.removeButtonSpacing = self.removeButtonSpacing
188216
configuration.backgroundColor = self.tagBackgroundColor
189217
configuration.cornerRadius = self.tagCornerRadius
218+
configuration.textSize = self.textSize
190219
configuration.textColor = self.tagTextColor
191220

192221
return configuration
@@ -318,24 +347,16 @@ extension HashtagView: UICollectionViewDelegateFlowLayout {
318347

319348
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
320349
let hashtag: HashTag = self.hashtags[indexPath.item]
321-
let textDimensions = hashtag.text.sizeOfString(usingFont: UIFont.systemFont(ofSize: 14.0))
350+
let wordSize = hashtag.text.sizeOfString(usingFont: UIFont.systemFont(ofSize: self.textSize))
322351

323352
var calculatedHeight = CGFloat()
324353
var calculatedWidth = CGFloat()
325354

326-
let configuration = makeConfiguration()
327-
328-
calculatedHeight = configuration.paddingTop + textDimensions.height + configuration.paddingBottom
355+
calculatedHeight = self.tagPaddingTop + wordSize.height + self.tagPaddingBottom
356+
calculatedWidth = self.tagPaddingLeft + wordSize.width + self.tagPaddingRight + 1
329357

330358
if hashtag.isRemovable {
331-
calculatedWidth =
332-
configuration.paddingLeft
333-
+ textDimensions.width
334-
+ configuration.removeButtonSpacing
335-
+ configuration.removeButtonSize
336-
+ configuration.paddingRight
337-
} else {
338-
calculatedWidth = configuration.paddingLeft + textDimensions.width + configuration.paddingRight
359+
calculatedWidth += self.removeButtonSize + self.removeButtonSpacing
339360
}
340361
return CGSize(width: calculatedWidth, height: calculatedHeight)
341362
}

Hashtags/Classes/RemovableHashtagCollectionViewCell.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ open class RemovableHashtagCollectionViewCell: UICollectionViewCell {
2727

2828
lazy var wordLabel : UILabel = {
2929
let lbl = UILabel()
30-
lbl.font = UIFont.systemFont(ofSize: 14)
3130
lbl.textColor = UIColor.white
31+
lbl.textAlignment = .center
32+
lbl.translatesAutoresizingMaskIntoConstraints = false
3233
return lbl
3334
}()
3435

3536
var removeButton : UIButton = {
3637
let btn = UIButton()
3738
let bundle = Bundle(for: RemovableHashtagCollectionViewCell.self)
3839
let removeIcon = UIImage(named: "close", in: bundle, compatibleWith: nil)!
40+
btn.translatesAutoresizingMaskIntoConstraints = false
3941
btn.setImage(removeIcon, for: .normal)
4042
btn.imageView?.contentMode = .scaleAspectFit
4143
btn.imageView?.tintColor = UIColor.black.withAlphaComponent(0.9)
@@ -57,14 +59,10 @@ open class RemovableHashtagCollectionViewCell: UICollectionViewCell {
5759

5860
private func setup() {
5961
self.clipsToBounds = true
60-
self.wordLabel.textAlignment = .center
6162

6263
self.addSubview(wordLabel)
6364
self.addSubview(removeButton)
6465

65-
self.wordLabel.translatesAutoresizingMaskIntoConstraints = false
66-
self.removeButton.translatesAutoresizingMaskIntoConstraints = false
67-
6866
// Text Width
6967
self.wordLabel.widthAnchor.constraint(greaterThanOrEqualToConstant: 10).isActive = true
7068
// Padding left
@@ -116,8 +114,10 @@ extension RemovableHashtagCollectionViewCell {
116114
self.removeButtonSpacingConstraint!.constant = configuration.removeButtonSpacing
117115
self.removeButtonWidthConstraint!.constant = configuration.removeButtonSize
118116

117+
self.layer.cornerRadius = configuration.cornerRadius
119118
self.backgroundColor = configuration.backgroundColor
119+
120120
self.wordLabel.textColor = configuration.textColor
121-
self.layer.cornerRadius = configuration.cornerRadius
121+
self.wordLabel.font = UIFont.systemFont(ofSize: configuration.textSize)
122122
}
123123
}

Untitled

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function review() {
2+
console.log("toto");
3+
}
4+
5+
module.exports = review;

0 commit comments

Comments
 (0)