Skip to content

Commit

Permalink
Resize detailTextLabel correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
tmdvs committed Oct 9, 2017
1 parent 8e4e2fd commit 215e1a6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion TDBadgedCell.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'TDBadgedCell'
s.version = '5.1'
s.version = '5.2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.summary = 'UITableViewCell subclass that adds a "badgeString" property to table view cells.'
s.description = <<-DESC
Expand Down
31 changes: 25 additions & 6 deletions TDBadgedCell/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -15,12 +18,28 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="BadgedCell" id="ezo-TG-RHv" customClass="TDBadgedCell" customModule="TDBadgedCell" customModuleProvider="target">
<rect key="frame" x="0.0" y="92" width="375" height="44"/>
<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">
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="ezo-TG-RHv" id="CnV-Wn-3rI">
<frame key="frameInset" width="375" height="43.5"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="1QD-aU-RcA">
<rect key="frame" x="16" y="5" width="33.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Subtitle" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="etl-XO-vZ9">
<rect key="frame" x="16" y="25.5" width="44" height="14.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
Expand All @@ -40,7 +59,7 @@
<objects>
<navigationController id="giq-3r-Yvd" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="6Ot-rJ-6tc">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
Expand Down
8 changes: 6 additions & 2 deletions TDBadgedCell/TDBadgedCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ open class TDBadgedCell: UITableViewCell {
badgeView.frame.origin.y = floor((frame.height / 2) - (badgeView.frame.height / 2))

// Now lets update the width of the cells text labels to take the badge into account
textLabel?.frame.size.width -= badgeView.frame.width + (offsetX * 2)
let labelWidth = self.contentView.frame.width - (badgeView.frame.width + (offsetX * 2)) - 20;

debugPrint(labelWidth)

textLabel?.frame.size.width = labelWidth
if((detailTextLabel) != nil) {
detailTextLabel?.frame.size.width -= badgeView.frame.width + (offsetX * 2)
detailTextLabel?.frame.size.width = labelWidth
}
}

Expand Down
1 change: 1 addition & 0 deletions TDBadgedCell/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ViewController: UITableViewController {


cell?.textLabel!.text = demoItems[indexPath.row]["title"]
cell?.detailTextLabel?.text = demoItems[indexPath.row]["title"]
cell?.badgeString = demoItems[indexPath.row]["badge"]!

// Set accessory views for two badges
Expand Down

0 comments on commit 215e1a6

Please sign in to comment.