Skip to content

Commit 215e1a6

Browse files
committed
Resize detailTextLabel correctly
1 parent 8e4e2fd commit 215e1a6

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

TDBadgedCell.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'TDBadgedCell'
3-
s.version = '5.1'
3+
s.version = '5.2'
44
s.license = { :type => 'MIT', :file => 'LICENSE' }
55
s.summary = 'UITableViewCell subclass that adds a "badgeString" property to table view cells.'
66
s.description = <<-DESC

TDBadgedCell/Base.lproj/Main.storyboard

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11198.2" systemVersion="16A294a" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="giq-3r-Yvd">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="giq-3r-Yvd">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
47
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
69
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
710
</dependencies>
811
<scenes>
@@ -15,12 +18,28 @@
1518
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1619
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
1720
<prototypes>
18-
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="BadgedCell" id="ezo-TG-RHv" customClass="TDBadgedCell" customModule="TDBadgedCell" customModuleProvider="target">
19-
<rect key="frame" x="0.0" y="92" width="375" height="44"/>
21+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="BadgedCell" textLabel="1QD-aU-RcA" detailTextLabel="etl-XO-vZ9" style="IBUITableViewCellStyleSubtitle" id="ezo-TG-RHv" customClass="TDBadgedCell" customModule="TDBadgedCell" customModuleProvider="target">
22+
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
2023
<autoresizingMask key="autoresizingMask"/>
2124
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="ezo-TG-RHv" id="CnV-Wn-3rI">
22-
<frame key="frameInset" width="375" height="43.5"/>
25+
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
2326
<autoresizingMask key="autoresizingMask"/>
27+
<subviews>
28+
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="1QD-aU-RcA">
29+
<rect key="frame" x="16" y="5" width="33.5" height="20.5"/>
30+
<autoresizingMask key="autoresizingMask"/>
31+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
32+
<nil key="textColor"/>
33+
<nil key="highlightedColor"/>
34+
</label>
35+
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Subtitle" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="etl-XO-vZ9">
36+
<rect key="frame" x="16" y="25.5" width="44" height="14.5"/>
37+
<autoresizingMask key="autoresizingMask"/>
38+
<fontDescription key="fontDescription" type="system" pointSize="12"/>
39+
<nil key="textColor"/>
40+
<nil key="highlightedColor"/>
41+
</label>
42+
</subviews>
2443
</tableViewCellContentView>
2544
</tableViewCell>
2645
</prototypes>
@@ -40,7 +59,7 @@
4059
<objects>
4160
<navigationController id="giq-3r-Yvd" sceneMemberID="viewController">
4261
<navigationBar key="navigationBar" contentMode="scaleToFill" id="6Ot-rJ-6tc">
43-
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
62+
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
4463
<autoresizingMask key="autoresizingMask"/>
4564
</navigationBar>
4665
<connections>

TDBadgedCell/TDBadgedCell.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@ open class TDBadgedCell: UITableViewCell {
5656
badgeView.frame.origin.y = floor((frame.height / 2) - (badgeView.frame.height / 2))
5757

5858
// Now lets update the width of the cells text labels to take the badge into account
59-
textLabel?.frame.size.width -= badgeView.frame.width + (offsetX * 2)
59+
let labelWidth = self.contentView.frame.width - (badgeView.frame.width + (offsetX * 2)) - 20;
60+
61+
debugPrint(labelWidth)
62+
63+
textLabel?.frame.size.width = labelWidth
6064
if((detailTextLabel) != nil) {
61-
detailTextLabel?.frame.size.width -= badgeView.frame.width + (offsetX * 2)
65+
detailTextLabel?.frame.size.width = labelWidth
6266
}
6367
}
6468

TDBadgedCell/ViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ViewController: UITableViewController {
3636

3737

3838
cell?.textLabel!.text = demoItems[indexPath.row]["title"]
39+
cell?.detailTextLabel?.text = demoItems[indexPath.row]["title"]
3940
cell?.badgeString = demoItems[indexPath.row]["badge"]!
4041

4142
// Set accessory views for two badges

0 commit comments

Comments
 (0)