8000 Add ability to set image on Row by ayanonagon · Pull Request #40 · venmo/Static · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add ability to set image on Row #40

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

Merged
merged 1 commit into from
Sep 4, 2015
Merged
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
6 changes: 6 additions & 0 deletions Example/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
23 changes: 23 additions & 0 deletions Example/Assets.xcassets/Settings.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Settings.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Settings@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "Settings@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 8000 Example/Assets.xcassets/Settings.imageset/Settings@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ViewController: TableViewController {
dataSource.sections = [
Section(header: "Styles", rows: [
Row(text: "Value 1", detailText: "Detail", cellClass: Value1Cell.self),
Row(text: "Value 1", detailText: "with an image", cellClass: Value1Cell.self, image: UIImage(named: "Settings")),
Row(text: "Value 2", detailText: "Detail", cellClass: Value2Cell.self),
Row(text: "Subtitle", detailText: "Detail", cellClass: SubtitleCell.self),
Row(text: "Button", detailText: "Detail", cellClass: ButtonCell.self, selection: { [unowned self] in
Expand Down
1 change: 1 addition & 0 deletions Static/CellType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extension CellType where Self: UITableViewCell {
public func configure(row row: Row) {
textLabel?.text = row.text
detailTextLabel?.text = row.detailText
imageView?.image = row.image
accessoryType = row.accessory.type
accessoryView = row.accessory.view
}
Expand Down
7 changes: 6 additions & 1 deletion Static/Row.swift
8000
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public struct Row: Hashable, Equatable {
/// Accessory for the row.
public var accessory: Accessory

/// Image for the row
public var image: UIImage?

/// Action to run when the row is selected.
public var selection: Selection?

Expand Down Expand Up @@ -130,11 +133,13 @@ public struct Row: Hashable, Equatable {

// MARK: - Initializers

public init(text: String? = nil, detailText: String? = nil, selection: Selection? = nil, accessory: Accessory = .None, cellClass: CellType.Type? = nil, context: Context? = nil, editActions: [EditAction] = [], UUID: String = NSUUID().UUIDString) {
public init(text: String? = nil, detailText: String? = nil, selection: Selection? = nil,
image: UIImage? = nil, accessory: Accessory = .None, cellClass: CellType.Type? = nil, context: Context? = nil, editActions: [EditAction] = [], UUID: String = NSUUID().UUIDString) {
self.UUID = UUID
self.text = text
self.detailText = detailText
self.selection = selection
self.image = image
self.accessory = accessory
self.cellClass = cellClass ?? Value1Cell.self
self.context = context
Expand Down
2 changes: 1 addition & 1 deletion Static/Tests/DataSourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DataSourceTests: XCTestCase {
let cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0))!
XCTAssertEqual("Merrily", cell.textLabel!.text!)
XCTAssertEqual("merrily", cell.detailTextLabel!.text!)
XCTAssertEqual(.DisclosureIndicator, cell.accessoryType)
XCTAssertEqual(UITableViewCellAccessoryType.DisclosureIndicator, cell.accessoryType)
}

func testExtremityTitles() {
Expand Down
10 changes: 8 additions & 2 deletions Static/Tests/RowTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ class RowTests: XCTestCase {

func testInit() {
let selection: Selection = {}
let context = [
let context: Row.Context = [
"Hello": "world"
]

let row = Row(text: "Title", detailText: "Detail", selection: selection, cellClass: ButtonCell.self, context: context, UUID: "1234")
XCTAssertEqual("1234", row.UUID)
XCTAssertEqual("Title", row.text!)
XCTAssertEqual("Detail", row.detailText!)
XCTAssertEqual(context["Hello"]!, row.context!["Hello"] as! String)
XCTAssertEqual("world", row.context?["Hello"] as? String)
}

func testInitWithImage() {
let image = UIImage(named: "Setting")
let row = Row(image: image)
XCTAssertEqual(row.image, image)
}

func testInitWithAccessoryType() {
Expand Down
0