Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dcordero committed Sep 1, 2017
0 parents commit feda2d4
Show file tree
Hide file tree
Showing 40 changed files with 1,275 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
.build/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output

.DS_Store
32 changes: 32 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
whitelist_rules:
- closing_brace
- colon
- comma
- control_statement
- custom_rules
- empty_count
- leading_whitespace
- legacy_cggeometry_functions
- legacy_constant
- legacy_constructor
- mark
- opening_brace
- operator_whitespace
- private_unit_test
- redundant_nil_coalesing
- redundant_string_enum_value
- return_arrow_whitespace
- syntactic_sugar
- trailing_semicolon
- void_return

excluded:
- TvOSCustomizableTableViewCell-Example/Pods

colon:
apply_to_dictionaries: false

custom_rules:
equal_sign_whitespace:
message: "Expected only one space before and after ="
regex: "(([ ]{2,}=)|(=[ ]{2,}))"
5 changes: 5 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import PackageDescription

let package = Package(
name: "TvOSCustomizableTableViewCell"
)
123 changes: 123 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# TvOSCustomizableTableViewCell

Light wrapper of UITableViewCell that allows extra customization for tvOS

![](art/Preview.gif)

## Description

TvOSCustomizableTableViewCell allows the customization of UITableViewCells in tvOS, adding extra properties to customize layout attributes which are not customizable on UITableViewCells out of the box.

Custom properties:

- Focused background color
- Unfocused background color
- Corner radius
- Scale factor when focused
- Shadow radius when focused
- Shadow opacity when focused
- Shadow color
- Shadow offset when focused
- Duration of the focus animation
- Title color when focuses/unfocused

Two color, linear gradient properties:

- Focused background end color
- Unfocused background end color
- gradient start & end points

A simple two color, linear gradient can be configured by setting either "background end" color properties. If neither "background end" color properties are set then TvOSCustomizableViewCell will use a solid background color by default.

## Requirements

- tvOS 9.0+
- Xcode 8.2

## Installation

### CocoaPods

To integrate TvOSCustomizableViewCell into your Xcode project using CocoaPods, specify it in your `Podfile`:

```ruby
source 'https://github.com/CocoaPods/Specs.git'
platform :tvos, '9.0'
use_frameworks!

target '<Your Target Name>' do
pod 'TvOSCustomizableTableViewCell', :git => 'https://github.com/zattoo/TvOSCustomizableTableViewCell.git'
end
```

### Manually

If you prefer, you can also integrate TvOSCustomizableViewCell into your project manually, just copying TvOSCustomizableViewCell.swift and GradientView.swift to your project.

## Usage

TvOSCustomizableViewCell can be integrated both programmatically or embedded in a xib file.

## Programmatically

TvOSCustomizableViewCell is a subclass of UITableViewCell, so it can be created and used as a regular TvOSCustomizableViewCell.

Example:
```swift
class ViewController: UIViewController, UITableViewDataSource {

private var tableView: UITableView!
var dataSource: UITableViewDataSource

// MARK: UIViewController

override func viewDidLoad() {
super.viewDidLoad()
setUpTableView()
}

// MARK: UITableViewDataSource

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TvOSCustomizableTableViewCell

cell.textLabel?.text = "Item \(indexPath.row)"
cell.focusedTitleColor = .black
cell.focusedBackgroundColor = .white
cell.focusedScaleFactor = 1.05

return cell
}

// MARK: Private

private func setUpTableView() {
tableView = UITableView()
tableView.frame = view.bounds
tableView.dataSource = self
tableView.register(TvOSCustomizableTableViewCell.self, forCellReuseIdentifier: "Cell")
view.addSubview(tableView)
}
}
```

## Embedded in a xib or storyboard file

Due to the fact that TvOSCustomizableTableViewCell is a subclass of UITableViewCell, the first step is to drag and drop a regular UITableView from the Object library to your view.

![](art/tableObjectLibrary.jpg)

Then change the value of "Custom Class" to "TvOSCustomizableTableViewCell", and the cell type to "Custom" to avoid the default focus behavior.

![](art/cellCustomClass.jpg) ![](art/cellTypeCustom.jpg)

And that's all...

The custom properties can be configured directly on the Storyboard using IBInspectables.

![](art/ibinspectables.png)

52 changes: 52 additions & 0 deletions Sources/GradientView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// GradientView.swift
// TvOSCustomizableTableViewCell
//
// Created by David Cordero on 02.09.16.
// Copyright © 2016 Zattoo, Inc. All rights reserved.
//

import UIKit

final class GradientView: UIView {

override class var layerClass: AnyClass {
return CAGradientLayer.self
}

var colors: [Any]? {
set {
gradientLayer.colors = newValue
}

get {
return gradientLayer.colors
}
}

var startPoint: CGPoint {
set {
gradientLayer.startPoint = newValue
}

get {
return gradientLayer.startPoint
}
}

var endPoint: CGPoint {
set {
gradientLayer.endPoint = newValue
}

get {
return gradientLayer.endPoint
}
}

// MARK: - Private

private lazy var gradientLayer: CAGradientLayer = {
return self.layer as! CAGradientLayer
}()
}
Loading

0 comments on commit feda2d4

Please sign in to comment.