pavankataria / SwiftDataTables

A Swift Data Table package, display grid-like data sets in a nicely formatted table for iOS. Subclassing UICollectionView that allows ordering, and searching with extensible options.
MIT License
448 stars 69 forks source link

Color Labels #8

Closed SLAppsDev closed 6 years ago

SLAppsDev commented 6 years ago

Hi, I was wondering if I could change the color of a column label based on a certain value, e.g. I have a list of value and if a value is less than 70% I would like to highlight it in red color, also could I change the whole row background color, e.g. every uneven row the background should be gray and even rows should be white background

is this possible?

Thanks for the library, great work on it!

pavankataria commented 6 years ago

Hey there @SLAppsDev, thanks for messaging about your request. There should already be code that allows this, but I may have commented it out. I'll get on it and will have something out by the weekend.

p.s. Also, could you share some more details about your app? It's great you're using this within your app, I aim to find out how others are using this package, I'll also be glad to put your app name onto the list of apps using this package to help spread the use of this package.

pavankataria commented 6 years ago

every uneven row the background should be gray and even rows should be white background

🎉 🎉 @SLAppsDev This is now available as of version 0.6.3 🎉 🎉 https://github.com/pavankataria/SwiftDataTables/releases/tag/0.6.3

There's two ways to achieve alternating colours. Both very simple.

1) Use the delegate methods:

func dataTable(_ dataTable: SwiftDataTable, highlightedColorForRowIndex at: Int) -> UIColor 
func dataTable(_ dataTable: SwiftDataTable, unhighlightedColorForRowIndex at: Int) -> UIColor

This allows you to specify the colours for rows for highlighted-columns as well as rows for unhighlighted columns.

2) Use the DataTableConfiguration object.

There's two properties you can override which otherwise have default values: highlightedAlternatingRowColors and unhighlightedAlternatingRowColors

This example is showcased in the Example project where a rainbow of alternating colours are shown. You provide an array of colours which SwiftDataTable will iterate over. So if you provide 7 colours in the highlightedAlternatingRowColors array then every 7 rows for the highlighted column will reflect the colours in your array.

Let me know how it goes. 🎉