Skip to content

Commit

Permalink
Merge branch 'master' into 2.0-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Watts committed Jul 29, 2019
2 parents a1f1da9 + 3a47675 commit 498d9e0
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 56 deletions.
1 change: 0 additions & 1 deletion .swift-version

This file was deleted.

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Version 2.0

- Support multiple thumbnails with UIStackView.
- Do not support iOS 9.0- anymore.

## Version 1.3

- Migrate to Xcode 10.2 and Swift 5
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

TimelineTableViewCell is a simple timeline view implemented by UITableViewCell. The UI design of TimelineTableViewCell is inspired by [ISTimeline](https://github.com/instant-solutions/ISTimeline).

[![CocoaPods](https://img.shields.io/cocoapods/dt/TimelineTableViewCell.svg)](https://cocoapods.org/pods/TimelineTableViewCell)
[![CocoaPods](https://img.shields.io/cocoapods/at/TimelineTableViewCell.svg)](https://cocoapods.org/pods/TimelineTableViewCell)
[![GitHub stars](https://img.shields.io/github/stars/kf99916/TimelineTableViewCell.svg)](https://github.com/kf99916/TimelineTableViewCell/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/kf99916/TimelineTableViewCell.svg)](https://github.com/kf99916/TimelineTableViewCell/network)
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/TimelineTableViewCell.svg)](https://cocoapods.org/pods/TimelineTableViewCell)
Expand All @@ -14,7 +12,7 @@ TimelineTableViewCell is a simple timeline view implemented by UITableViewCell.

## Requirements

- iOS 8.0 or higher
- iOS 9.0 or higher

### v1.0.1-

Expand All @@ -28,6 +26,11 @@ TimelineTableViewCell is a simple timeline view implemented by UITableViewCell.

- Swift 5

### v2.0

- Breaking Changes for v1.3-: thumbnailImageView is replaced with UIStackView to support multiple thumbnails.
- Do not support iOS9.0- anymore.

## Installation

```ruby
Expand Down Expand Up @@ -94,7 +97,7 @@ TimelinePoint()
The line in the cell is represented by a Timeline object and is divided by the point as the front line and the backline.
`var width: CGFloat` the thickness of the line (default `2.0`)
`var frontColor: UIColor` the color of the front line (defalut `UIColor.black`)
`var backColor: UIColor` the color of the back line (defalut `UIColor.black`)
`var backColor: UIColor` the color of the back line (defalut `UIColor.black`)
`var leftMargin: CGFloat` the left margin of the line (default `60.0`)

#### Initializers
Expand All @@ -121,6 +124,7 @@ The cell is represented by a TimelineTableViewCell object.
`illustrationImageView: UIImageView!` the illustration
`var bubbleRadius: CGFloat` the radius of the bubble corners (default `2.0`)
`var bubbleColor: UIColor` the color of every bubble (default `.init(red: 0.75, green: 0.75, blue: 0.75, alpha: 1.0)`)
`viewsInStackView: [UIView]` the views in the stack view.

## Apps using TimelineTableViewCell

Expand Down
4 changes: 2 additions & 2 deletions TimelineTableViewCell.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'TimelineTableViewCell'
s.version = '1.3'
s.version = '2.0'
s.summary = 'Simple timeline view implemented by UITableViewCell'

# This description is used to generate tags and improve search results.
Expand All @@ -26,7 +26,7 @@ Pod::Spec.new do |s|
s.source = { :git => 'https://github.com/kf99916/TimelineTableViewCell.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

s.ios.deployment_target = '8.0'
s.ios.deployment_target = '9.0'

s.source_files = 'TimelineTableViewCell/**/*.swift'

Expand Down
4 changes: 2 additions & 2 deletions TimelineTableViewCell.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -377,7 +377,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand Down
7 changes: 5 additions & 2 deletions TimelineTableViewCell/Timeline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ public struct Timeline {
draw(view: view, from: start, to: middle, color: frontColor)
draw(view: view, from: middle, to: end, color: backColor)
}

fileprivate func draw(view: UIView, from: CGPoint, to: CGPoint, color: UIColor) {
}

// MARK: - Fileprivate Methods
fileprivate extension Timeline {
func draw(view: UIView, from: CGPoint, to: CGPoint, color: UIColor) {
let path = UIBezierPath()
path.move(to: from)
path.addLine(to: to)
Expand Down
50 changes: 45 additions & 5 deletions TimelineTableViewCell/TimelineTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ open class TimelineTableViewCell: UITableViewCell {
@IBOutlet weak open var titleLabel: UILabel!
@IBOutlet weak open var descriptionLabel: UILabel!
@IBOutlet weak open var lineInfoLabel: UILabel!
@IBOutlet weak open var thumbnailImageView: UIImageView!
@IBOutlet weak internal var stackView: UIStackView!
@IBOutlet weak open var illustrationImageView: UIImageView!

@IBOutlet weak var titleLabelLeftMargin: NSLayoutConstraint!
@IBOutlet weak var lineInfoLabelRightMargin: NSLayoutConstraint!
@IBOutlet weak var descriptionMargin: NSLayoutConstraint!
@IBOutlet weak var illustrationSize: NSLayoutConstraint!
@IBOutlet weak var thumbnailSize: NSLayoutConstraint!
@IBOutlet weak var stackViewSize: NSLayoutConstraint!

open var viewsInStackView: [UIView] = []

open var timelinePoint = TimelinePoint() {
didSet {
Expand All @@ -47,6 +49,8 @@ open class TimelineTableViewCell: UITableViewCell {

open var bubbleColor = UIColor(red: 0.75, green: 0.75, blue: 0.75, alpha: 1.0)
open var bubbleEnabled = true

fileprivate lazy var maxNumSubviews = Int(floor(stackView.frame.size.width / (stackView.frame.size.height + stackView.spacing))) - 1

override open func awakeFromNib() {
super.awakeFromNib()
Expand Down Expand Up @@ -88,9 +92,45 @@ open class TimelineTableViewCell: UITableViewCell {
if bubbleEnabled {
drawBubble()
}

stackView.arrangedSubviews.forEach { view in
stackView.removeArrangedSubview(view)
view.removeFromSuperview()
}

let views = viewsInStackView.count <= maxNumSubviews ? viewsInStackView : Array(viewsInStackView[0..<maxNumSubviews])
views.forEach { view in
view.translatesAutoresizingMaskIntoConstraints = false
view.addConstraint(NSLayoutConstraint(item: view,
attribute: NSLayoutConstraint.Attribute.width,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: view,
attribute: NSLayoutConstraint.Attribute.height,
multiplier: 1,
constant: 0))
view.contentMode = .scaleAspectFill
view.clipsToBounds = true
stackView.addArrangedSubview(view)
}

let diffNumViews = viewsInStackView.count - maxNumSubviews
if diffNumViews > 0 {
let label = UILabel(frame: CGRect.zero)
label.text = String(format: "+ %d", diffNumViews)
label.font = UIFont.preferredFont(forTextStyle: .headline)
stackView.addArrangedSubview(label)
}
else {
let spacerView = UIView()
spacerView.setContentHuggingPriority(.defaultLow, for: .horizontal)
stackView.addArrangedSubview(spacerView)
}
}

fileprivate func drawBubble() {
}

// MARK: - Fileprivate Methods
fileprivate extension TimelineTableViewCell {
func drawBubble() {
let padding: CGFloat = 8
let bubbleRect = CGRect(
x: titleLabelLeftMargin.constant - padding,
Expand All @@ -104,7 +144,7 @@ open class TimelineTableViewCell: UITableViewCell {
path.addLine(to: startPoint)
path.addLine(to: CGPoint(x: bubbleRect.origin.x - 8, y: bubbleRect.origin.y + bubbleRect.height / 2))
path.addLine(to: CGPoint(x: bubbleRect.origin.x, y: bubbleRect.origin.y + bubbleRect.height / 2 + 8))

let shapeLayer = CAShapeLayer()
shapeLayer.path = path.cgPath
shapeLayer.fillColor = bubbleColor.cgColor
Expand Down
60 changes: 30 additions & 30 deletions TimelineTableViewCell/TimelineTableViewCell.xib
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -11,74 +11,74 @@
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="mx5-YM-BCr" customClass="TimelineTableViewCell" customModule="Timeline" customModuleProvider="target">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="mx5-YM-BCr" customClass="TimelineTableViewCell" customModule="TimelineTableViewCell" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="375" height="88"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="mx5-YM-BCr" id="HxZ-h8-hOq">
<rect key="frame" x="0.0" y="0.0" width="375" height="87.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="right" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="W66-Ck-wDF">
<rect key="frame" x="55" y="61" width="0.0" height="0.0"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption2"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4Od-hl-ENS">
<rect key="frame" x="88" y="34" width="0.0" height="0.0"/>
<rect key="frame" x="88" y="23" width="0.0" height="0.0"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="LWm-f0-Lj3">
<rect key="frame" x="88" y="56" width="271" height="21"/>
<rect key="frame" x="88" y="45" width="271" height="32"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption1"/>
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="2Rz-dN-Xtc">
<rect key="frame" x="106" y="19" width="30" height="30"/>
<stackView opaque="NO" contentMode="scaleToFill" alignment="center" spacing="5" translatesAutoresizingMaskIntoConstraints="NO" id="Bvw-S8-TSj">
<rect key="frame" x="106" y="8" width="253" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="30" id="KXK-HQ-Kqp"/>
<constraint firstAttribute="width" secondItem="2Rz-dN-Xtc" secondAttribute="height" multiplier="1:1" id="YyW-BV-Uvn"/>
<constraint firstAttribute="height" constant="30" id="bzB-CF-D30"/>
</constraints>
</imageView>
</stackView>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="aFP-zW-cVP">
<rect key="frame" x="39" y="26" width="16" height="16"/>
<rect key="frame" x="39" y="15" width="16" height="16"/>
<constraints>
<constraint firstAttribute="width" constant="16" id="PXT-6u-JPT"/>
<constraint firstAttribute="width" secondItem="aFP-zW-cVP" secondAttribute="height" multiplier="1:1" id="aMd-vc-LxB"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="right" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="W66-Ck-wDF">
<rect key="frame" x="55" y="66.5" width="0.0" height="0.0"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption2"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="2Rz-dN-Xtc" firstAttribute="leading" secondItem="4Od-hl-ENS" secondAttribute="trailing" constant="18" id="1cR-v5-lWY"/>
<constraint firstItem="LWm-f0-Lj3" firstAttribute="top" secondItem="4Od-hl-ENS" secondAttribute="bottom" constant="22" id="3rS-ql-g6Q"/>
<constraint firstItem="4Od-hl-ENS" firstAttribute="centerY" secondItem="2Rz-dN-Xtc" secondAttribute="centerY" id="6P6-hc-aYO"/>
<constraint firstItem="Bvw-S8-TSj" firstAttribute="top" secondItem="HxZ-h8-hOq" secondAttribute="top" constant="8" id="Pvp-pi-ekz"/>
<constraint firstItem="4Od-hl-ENS" firstAttribute="leading" secondItem="HxZ-h8-hOq" secondAttribute="leading" constant="88" id="W5Z-YV-Yjl"/>
<constraint firstAttribute="bottomMargin" secondItem="LWm-f0-Lj3" secondAttribute="bottom" id="XMs-7H-S0s"/>
<constraint firstItem="2Rz-dN-Xtc" firstAttribute="top" secondItem="HxZ-h8-hOq" secondAttribute="topMargin" constant="8" id="Xh2-mj-c44"/>
<constraint firstAttribute="trailing" secondItem="Bvw-S8-TSj" secondAttribute="trailing" constant="16" id="aad-WB-WNL"/>
<constraint firstItem="LWm-f0-Lj3" firstAttribute="centerY" secondItem="W66-Ck-wDF" secondAttribute="centerY" id="aeo-Ux-Iwh"/>
<constraint firstItem="W66-Ck-wDF" firstAttribute="trailing" secondItem="HxZ-h8-hOq" secondAttribute="leading" constant="55" id="ngi-V5-gD4"/>
<constraint firstItem="LWm-f0-Lj3" firstAttribute="top" secondItem="4Od-hl-ENS" secondAttribute="bottom" constant="22" id="jMi-d8-WUj"/>
<constraint firstItem="Bvw-S8-TSj" firstAttribute="leading" secondItem="4Od-hl-ENS" secondAttribute="trailing" constant="18" id="jZ2-fn-rkf"/>
<constraint firstItem="W66-Ck-wDF" firstAttribute="trailing" secondItem="HxZ-h8-hOq" secondAttribute="leading" constant="55" id="ngi-V5-gD4" userLabel="Line Info Label Right Margin"/>
<constraint firstItem="aFP-zW-cVP" firstAttribute="trailing" secondItem="W66-Ck-wDF" secondAttribute="trailing" id="o7X-wK-V0y"/>
<constraint firstItem="LWm-f0-Lj3" firstAttribute="trailing" secondItem="HxZ-h8-hOq" secondAttribute="trailingMargin" id="oYD-h6-WyT"/>
<constraint firstItem="4Od-hl-ENS" firstAttribute="centerY" secondItem="aFP-zW-cVP" secondAttribute="centerY" id="pek-Dw-jRh"/>
<constraint firstItem="LWm-f0-Lj3" firstAttribute="leading" secondItem="4Od-hl-ENS" secondAttribute="leading" id="rAr-3k-rob"/>
<constraint firstItem="Bvw-S8-TSj" firstAttribute="centerY" secondItem="4Od-hl-ENS" secondAttribute="centerY" id="zMY-zh-scu"/>
<constraint firstItem="LWm-f0-Lj3" firstAttribute="leading" secondItem="4Od-hl-ENS" secondAttribute="leading" id="zXz-ua-Ul2"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="descriptionLabel" destination="LWm-f0-Lj3" id="fpE-cB-Cup"/>
<outlet property="descriptionMargin" destination="3rS-ql-g6Q" id="idx-fg-Roy"/>
<outlet property="descriptionMargin" destination="jMi-d8-WUj" id="c2m-Hd-IRc"/>
<outlet property="illustrationImageView" destination="aFP-zW-cVP" id="9AD-3h-Weg"/>
<outlet property="illustrationSize" destination="PXT-6u-JPT" id="UPw-bp-Fs7"/>
<outlet property="illustrationSize" destination="PXT-6u-JPT" id="rJ5-Sp-UeA"/>
<outlet property="lineInfoLabel" destination="W66-Ck-wDF" id="WZr-av-HnT"/>
<outlet property="lineInfoLabelRightMargin" destination="ngi-V5-gD4" id="Rwv-ts-z94"/>
<outlet property="thumbnailImageView" destination="2Rz-dN-Xtc" id="hFp-fW-txb"/>
<outlet property="thumbnailSize" destination="KXK-HQ-Kqp" id="5W5-9C-Wq7"/>
<outlet property="lineInfoLabelRightMargin" destination="ngi-V5-gD4" id="vdq-ke-ck1"/>
<outlet property="stackView" destination="Bvw-S8-TSj" id="Bkp-gf-6w5"/>
<outlet property="stackViewSize" destination="bzB-CF-D30" id="a5u-SW-P0g"/>
<outlet property="titleLabel" destination="4Od-hl-ENS" id="Zc2-fd-i6t"/>
<outlet property="titleLabelLeftMargin" destination="W5Z-YV-Yjl" id="xUn-7D-bME"/>
<outlet property="titleLabelLeftMargin" destination="W5Z-YV-Yjl" id="600-ki-hNG"/>
</connections>
<point key="canvasLocation" x="28" y="98.950524737631198"/>
<point key="canvasLocation" x="28" y="64.767616191904054"/>
</tableViewCell>
</objects>
</document>
Loading

0 comments on commit 498d9e0

Please sign in to comment.