Skip to content

Commit

Permalink
support individually coloring fields...
Browse files Browse the repository at this point in the history
  • Loading branch information
clayallsopp committed Nov 5, 2012
1 parent 83c3cbc commit 4d2aad7
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 11 deletions.
40 changes: 34 additions & 6 deletions examples/Styling/app/app_delegate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,45 @@ def application(application, didFinishLaunchingWithOptions:launchOptions)
}, {
title: "Font Color",
rows: [{
title: "White on Red",
title: "All Red",
type: :string,
value: "Red Everything",
style: {
background_color: "red",
font_color: "white"
font_color: "red"
}
}, {
title: "Red Title",
type: :text,
value: "Purple value",
style: {
font_color: {
title: "red",
value: "purple"
}
}
}, {
title: "Success!",
type: :string,
subtitle: "It worked",
value: "This is normal",
style: {
font_color: {
title: "09A41D",
subtitle: "09A41D"
}
}
}, {
title: "Blue on Gradient",
type: :string,
value: "I'm blue",
style: {
background_color: {
top: "ffffff",
bottom: "dddddd"
},
font_color: "0088cc"
font_color: {
value: "0088cc"
}
}
}]
}, {
Expand All @@ -82,15 +106,18 @@ def application(application, didFinishLaunchingWithOptions:launchOptions)
}
}, {
title: "Green to Purple",
subtitle: "Tap me",
type: :string,
style: {
selection_color: {
top: "green",
bottom: "purple"
bottom: "purple",
font_color: "red"
}
}
}, {
title: "Square",
subtitle: "A subtle touch",
type: :string,
style: {
background_color: {
Expand All @@ -99,7 +126,8 @@ def application(application, didFinishLaunchingWithOptions:launchOptions)
},
selection_color: {
top: "eeeeee",
bottom: "dddddd"
bottom: "dddddd",
font_color: "none"
}
}
}]
Expand Down
22 changes: 18 additions & 4 deletions lib/formotion/style/font_color_style.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Formotion
module RowStyle
class FontColorStyle < Base
PROPERTIES = [:color].each { |prop|
PROPERTIES = [:color, :title, :subtitle, :value].each { |prop|
attr_accessor prop
}

Expand All @@ -10,11 +10,25 @@ def self.default_object_key
end

def setup_cell(cell)
cell.subviews_recursive_each do |subview|
if subview.respond_to? "setTextColor:"
subview.setTextColor(self.color.to_color)
if self.color
cell.subviews_recursive_each do |subview|
if subview.respond_to? "setTextColor:"
subview.setTextColor(self.color.to_color)
end
end
end

if self.title
cell.textLabel.setTextColor(self.title.to_color)
end

if self.subtitle
cell.detailTextLabel.setTextColor(self.subtitle.to_color)
end

if self.value
self.row.text_field.setTextColor(self.value.to_color)
end
end
end
end
Expand Down
11 changes: 10 additions & 1 deletion lib/formotion/style/selection_color_style.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Formotion
module RowStyle
class SelectionColorStyle < Base
PROPERTIES = [:color, :top, :bottom].each { |prop|
PROPERTIES = [:color, :top, :bottom, :font_color].each { |prop|
attr_accessor prop
}

Expand All @@ -28,6 +28,15 @@ def setup_cell(cell)

cell.selectedBackgroundView.colors = [top_color, bottom_color]
end

if self.font_color
cell.subviews_recursive_each do |subview|
if subview.respond_to?("setHighlightedTextColor:")
using_color = (self.font_color == "none") ? subview.textColor : self.font_color.to_color
subview.setHighlightedTextColor(using_color)
end
end
end
end

def will_display(cell)
Expand Down
5 changes: 5 additions & 0 deletions spec/styling/font_color_style_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe "FontColorStyle" do
it "should be true" do
true.should == true
end
end

0 comments on commit 4d2aad7

Please sign in to comment.