Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added customization options for configuration to allow more styling #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Example/DemoSwiftDataTables/MenuTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ extension MenuViewController {
section.append(MenuItem(title: "Without scroll bars", config: configurationWithoutScrollBars()))
section.append(MenuItem(title: "Alternating colours", config: configurationAlternatingColours()))
section.append(MenuItem(title: "Fixed/Frozen columns", config: configurationFixedColumns()))
section.append(MenuItem(title: "With borders", config: configurationBorders()))
section.append(MenuItem(title: "Header with background colour", config: configurationColouredHeader()))
section.append(MenuItem(title: "With centered text", config: configurationCenteredText()))
return section
}
}
Expand Down Expand Up @@ -225,6 +228,27 @@ extension MenuViewController {
]
return configuration
}

private func configurationBorders() -> DataTableConfiguration {
var configuration = DataTableConfiguration()
configuration.shouldShowDataBorders = true
configuration.shouldShowHeaderFooterBorders = true
return configuration
}

private func configurationCenteredText() -> DataTableConfiguration {
var configuration = DataTableConfiguration()
configuration.dataTextAlignment = .center
configuration.headerFooterTextAlignment = .center
return configuration
}

private func configurationColouredHeader() -> DataTableConfiguration {
var configuration = DataTableConfiguration()
configuration.headerFooterBackgroundColor = UIColor(1, 0.90, 0.90)
return configuration
}

private func configurationFixedColumns() -> DataTableConfiguration {
var configuration = DataTableConfiguration()
configuration.fixedColumns = DataTableFixedColumnType(leftColumns: 1, rightColumns: 1)
Expand Down
6 changes: 6 additions & 0 deletions SwiftDataTables/Classes/DataCell/DataCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@ class DataCell: UICollectionViewCell {
func setup(_ viewModel: DataCellViewModel){
self.dataLabel.text = viewModel.data.stringRepresentation
// self.contentView.backgroundColor = .white
self.dataLabel.textAlignment = viewModel.dataTextAlignement ?? .natural
guard let showBorders = viewModel.shouldShowDataBorders else { return }
if showBorders {
self.layer.borderWidth = 1.0
self.layer.borderColor = UIColor.black.cgColor
}
}
}
16 changes: 14 additions & 2 deletions SwiftDataTables/Classes/DataCell/DataCellViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import Foundation
import UIKit

open class DataCellViewModel: VirtualPositionTrackable, CollectionViewCellRepresentable {

//MARK: - Private Properties
private var dataTableConfiguration: DataTableConfiguration?

//MARK: - Public Properties
var xPositionRunningTotal: CGFloat? = nil
var yPositionRunningTotal: CGFloat? = nil
Expand All @@ -21,9 +23,19 @@ open class DataCellViewModel: VirtualPositionTrackable, CollectionViewCellRepres
public var stringRepresentation: String {
return self.data.stringRepresentation
}

public var shouldShowDataBorders: Bool? {
return dataTableConfiguration?.shouldShowDataBorders ?? false
}

public var dataTextAlignement: NSTextAlignment? {
return dataTableConfiguration?.dataTextAlignment ?? .natural
}

//MARK: - Lifecycle
init(data: DataTableValueType){
init(data: DataTableValueType, dataTableConfiguration: DataTableConfiguration?){
self.data = data
self.dataTableConfiguration = dataTableConfiguration
}

static func registerCell(collectionView: UICollectionView) {
Expand Down
8 changes: 8 additions & 0 deletions SwiftDataTables/Classes/HeaderFooter/DataHeaderFooter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import UIKit
class DataHeaderFooter: UICollectionReusableView {

//MARK: - Properties
@IBOutlet var backgroundView: UIView!
@IBOutlet var titleLabel: UILabel!
@IBOutlet var sortingImageView: UIImageView!

Expand All @@ -26,9 +27,16 @@ class DataHeaderFooter: UICollectionReusableView {

func setup(viewModel: DataHeaderFooterViewModel) {
self.titleLabel.text = viewModel.data
self.titleLabel.textAlignment = viewModel.headerFooterTextAlignment ?? .natural
self.sortingImageView.image = viewModel.imageForSortingElement
self.sortingImageView.tintColor = viewModel.tintColorForSortingElement
self.backgroundColor = .white
self.backgroundView.backgroundColor = viewModel.backgroundColorForHeaderFooter ?? UIColor.clear
guard let showBorders = viewModel.shouldShowHeaderFooterBorders else { return }
if showBorders {
self.layer.borderWidth = 1.0
self.layer.borderColor = UIColor.black.cgColor
}
}
@objc func didTapView(){
self.didTapEvent?()
Expand Down
20 changes: 13 additions & 7 deletions SwiftDataTables/Classes/HeaderFooter/DataHeaderFooter.xib
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14868" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14824"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -16,6 +13,10 @@
<rect key="frame" x="0.0" y="0.0" width="80" height="70"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="AeC-ok-Lpa">
<rect key="frame" x="0.0" y="0.0" width="80" height="70"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="ID" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6ld-fA-9ry">
<rect key="frame" x="15" y="5" width="35" height="60"/>
<constraints>
Expand All @@ -26,22 +27,27 @@
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="3b5-XP-sWJ">
<rect key="frame" x="55" y="21" width="20" height="29"/>
<rect key="frame" x="55" y="20.5" width="20" height="29"/>
<constraints>
<constraint firstAttribute="width" constant="20" id="PSY-E0-2Fg"/>
<constraint firstAttribute="width" secondItem="3b5-XP-sWJ" secondAttribute="height" multiplier="9:13" id="Y7W-7N-ryB"/>
</constraints>
</imageView>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="AeC-ok-Lpa" secondAttribute="bottom" id="3fO-mo-aXx"/>
<constraint firstAttribute="trailing" secondItem="3b5-XP-sWJ" secondAttribute="trailing" constant="5" id="C1O-2a-f4t"/>
<constraint firstItem="6ld-fA-9ry" firstAttribute="top" secondItem="U6b-Vx-4bR" secondAttribute="top" constant="5" id="EME-7U-ucS"/>
<constraint firstAttribute="trailing" secondItem="AeC-ok-Lpa" secondAttribute="trailing" id="FQZ-Uc-tl6"/>
<constraint firstItem="AeC-ok-Lpa" firstAttribute="top" secondItem="U6b-Vx-4bR" secondAttribute="top" id="aT0-iS-PQP"/>
<constraint firstItem="6ld-fA-9ry" firstAttribute="leading" secondItem="U6b-Vx-4bR" secondAttribute="leading" constant="15" id="aav-LF-Zed"/>
<constraint firstItem="3b5-XP-sWJ" firstAttribute="leading" secondItem="6ld-fA-9ry" secondAttribute="trailing" constant="5" id="dLW-GI-2ij"/>
<constraint firstAttribute="bottom" secondItem="6ld-fA-9ry" secondAttribute="bottom" constant="5" id="pWD-9e-WRg"/>
<constraint firstItem="AeC-ok-Lpa" firstAttribute="leading" secondItem="U6b-Vx-4bR" secondAttribute="leading" id="vcc-T8-dZP"/>
<constraint firstItem="3b5-XP-sWJ" firstAttribute="centerY" secondItem="U6b-Vx-4bR" secondAttribute="centerY" id="yOq-yL-RPj"/>
</constraints>
<connections>
<outlet property="backgroundView" destination="AeC-ok-Lpa" id="nEB-Qz-GKr"/>
<outlet property="sortingImageView" destination="3b5-XP-sWJ" id="KN1-nU-S9r"/>
<outlet property="titleLabel" destination="6ld-fA-9ry" id="JR0-D8-ucs"/>
</connections>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ public class DataHeaderFooterViewModel: DataTableSortable {
var tintColorForSortingElement: UIColor? {
return (dataTable != nil && sortType != .unspecified) ? dataTable.options.sortArrowTintColor : UIColor.gray
}

var backgroundColorForHeaderFooter: UIColor? {
return (dataTable != nil) ? dataTable.options.headerFooterBackgroundColor : UIColor.white
}

var shouldShowHeaderFooterBorders: Bool? {
return (dataTable != nil) ? dataTable.options.shouldShowHeaderFooterBorders : false
}

var headerFooterTextAlignment: NSTextAlignment? {
return (dataTable != nil) ? dataTable.options.headerFooterTextAlignment : .natural
}

//MARK: - Events

Expand Down
7 changes: 7 additions & 0 deletions SwiftDataTables/Classes/Models/DataTableConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public struct DataTableConfiguration: Equatable {
public var heightForSearchView: CGFloat = 60
public var heightOfInterRowSpacing: CGFloat = 1

public var shouldShowDataBorders: Bool = false
public var shouldShowHeaderFooterBorders: Bool = false
public var shouldShowFooter: Bool = true
public var shouldShowSearchSection: Bool = true
public var shouldSearchHeaderFloat: Bool = false
Expand All @@ -49,6 +51,11 @@ public struct DataTableConfiguration: Equatable {
]

public var fixedColumns: DataTableFixedColumnType? = nil

public var headerFooterBackgroundColor: UIColor = UIColor.white

public var dataTextAlignment: NSTextAlignment = .natural
public var headerFooterTextAlignment: NSTextAlignment = .natural

public init(){

Expand Down
3 changes: 2 additions & 1 deletion SwiftDataTables/Classes/SwiftDataTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,15 @@ public extension SwiftDataTable {
data: dataStructure.footerTitles[$0],
sortType: sortTypeForFooter
)
headerViewModel.configure(dataTable: self, columnIndex: $0)
return headerViewModel
}

//2. Create the view models
//let viewModels: DataTableViewModelContent =
self.rowViewModels = dataStructure.data.map{ currentRowData in
return currentRowData.map {
return DataCellViewModel(data: $0)
return DataCellViewModel(data: $0, dataTableConfiguration: options)
}
}
self.paginationViewModel = PaginationHeaderViewModel()
Expand Down