mirror of
https://github.com/zhigang1992/rmq.git
synced 2026-01-12 17:52:17 +08:00
Added options to create, append, prepend. Tests for those coming later. Added to UILabel and UIView stylers
This commit is contained in:
@@ -11,6 +11,18 @@ module RubyMotionQuery
|
||||
def color=(value) ; @view.textColor = value ; end
|
||||
def color ; @view.textColor ; end
|
||||
|
||||
def number_of_lines=(value)
|
||||
value = 0 if value == :unlimited
|
||||
@view.numberOfLines = value
|
||||
end
|
||||
def number_of_lines
|
||||
if @view.numberOfLines == 0
|
||||
:unlimited
|
||||
else
|
||||
@view.numberOfLines
|
||||
end
|
||||
end
|
||||
|
||||
def text_alignment=(value)
|
||||
@view.textAlignment = TEXT_ALIGNMENTS[value] || value
|
||||
end
|
||||
@@ -23,6 +35,7 @@ module RubyMotionQuery
|
||||
end
|
||||
alias :size_to_fit :resize_to_fit_text
|
||||
|
||||
|
||||
TEXT_ALIGNMENTS = {
|
||||
left: NSTextAlignmentLeft,
|
||||
center: NSTextAlignmentCenter,
|
||||
|
||||
@@ -24,6 +24,14 @@ module RubyMotionQuery
|
||||
end
|
||||
alias :parent :superview
|
||||
|
||||
def super_height
|
||||
@view.superview.frame.size.height
|
||||
end
|
||||
|
||||
def super_width
|
||||
@view.superview.frame.size.width
|
||||
end
|
||||
|
||||
def tag(tags)
|
||||
rmq(@view).tag(tags)
|
||||
end
|
||||
@@ -189,7 +197,9 @@ module RubyMotionQuery
|
||||
@view.backgroundColor
|
||||
end
|
||||
|
||||
# TODO add background_image_tiled
|
||||
def background_image=(value)
|
||||
@view.backgroundColor = UIColor.colorWithPatternImage(value)
|
||||
end
|
||||
|
||||
def z_position=(index)
|
||||
@view.layer.zPosition = index
|
||||
|
||||
@@ -58,7 +58,7 @@ module RubyMotionQuery
|
||||
when UILabel then Stylers::UILabelStyler.new(view)
|
||||
when UIButton then Stylers::UIButtonStyler.new(view)
|
||||
when UIImageView then Stylers::UIImageViewStyler.new(view)
|
||||
when UIScrollView then Stylers::UIScrollViewStyler.new(view)
|
||||
when UITableView then Stylers::UITableViewStyler.new(view)
|
||||
when UISwitch then Stylers::UISwitchStyler.new(view)
|
||||
when UIDatePicker then Stylers::UIDatePickerStyler.new(view)
|
||||
when UISegmentedControl then Stylers::UISegmentedControlStyler.new(view)
|
||||
@@ -67,11 +67,11 @@ module RubyMotionQuery
|
||||
when UISlider then Stylers::UISliderStyler.new(view)
|
||||
when UIStepper then Stylers::UIStepperStyler.new(view)
|
||||
when UITabBar then Stylers::UITabBarStyler.new(view)
|
||||
when UITableView then Stylers::UITableViewStyler.new(view)
|
||||
when UITableViewCell then Stylers::UITableViewCellStyler.new(view)
|
||||
when UITextView then Stylers::UITextViewStyler.new(view)
|
||||
when UITextField then Stylers::UITextFieldStyler.new(view)
|
||||
when UINavigationBar then Stylers::UINavigationBarStyler.new(view)
|
||||
when UIScrollView then Stylers::UIScrollViewStyler.new(view)
|
||||
# TODO, all the controls are done, but missing some views, add
|
||||
when UIControl then Stylers::UIControlStyler.new(view)
|
||||
else
|
||||
|
||||
@@ -47,13 +47,16 @@ module RubyMotionQuery
|
||||
alias :insert :add_subview
|
||||
|
||||
# @return [RMQ]
|
||||
def append(view_or_constant, style=nil)
|
||||
add_subview(view_or_constant, style: style)
|
||||
def append(view_or_constant, style=nil, opts = {})
|
||||
opts[:style] = style
|
||||
add_subview(view_or_constant, opts)
|
||||
end
|
||||
|
||||
# @return [RMQ]
|
||||
def unshift(view_or_constant, style = nil)
|
||||
add_subview view_or_constant, style: style, at_index: 0
|
||||
def unshift(view_or_constant, style=nil, opts = {})
|
||||
opts[:at_index] = 0
|
||||
opts[:style] = style
|
||||
add_subview view_or_constant, opts
|
||||
end
|
||||
alias :prepend :unshift
|
||||
|
||||
@@ -66,7 +69,7 @@ module RubyMotionQuery
|
||||
# @example
|
||||
# def tableView(table_view, cellForRowAtIndexPath: index_path)
|
||||
# cell = tableView.dequeueReusableCellWithIdentifier(CELL_IDENTIFIER) || begin
|
||||
# rmq.create(StoreCell, :store_cell)
|
||||
# rmq.create(StoreCell, :store_cell, reuse_identifier: CELL_IDENTIFIER)
|
||||
# end
|
||||
# end
|
||||
#
|
||||
@@ -76,9 +79,11 @@ module RubyMotionQuery
|
||||
# end
|
||||
# end
|
||||
#
|
||||
def create(view_or_constant, style = nil)
|
||||
def create(view_or_constant, style = nil, opts = {})
|
||||
# TODO, refactor so that add_subview uses create, not backwards like it is now
|
||||
add_subview view_or_constant, style: style, do_not_add: true
|
||||
opts[:do_not_add] = true
|
||||
opts[:style] = style
|
||||
add_subview view_or_constant, opts
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
@@ -44,6 +44,7 @@ class SyleSheetForUIViewStylerTests < RubyMotionQuery::Stylesheet
|
||||
st.opaque = false
|
||||
|
||||
st.background_color = color.red
|
||||
# TODO test background_image
|
||||
|
||||
st.scale = 1.5
|
||||
end
|
||||
@@ -98,7 +99,7 @@ shared 'styler' do
|
||||
view.layer.zPosition.should == 99
|
||||
end
|
||||
|
||||
|
||||
# TODO, test super_height and super_width
|
||||
|
||||
it 'should apply a style with every UIViewStyler wrapper method' do
|
||||
view = @vc.rmq.append(@view_klass, :ui_view_kitchen_sink).get
|
||||
|
||||
@@ -5,7 +5,7 @@ class SyleSheetForUIViewStylerTests < RubyMotionQuery::Stylesheet
|
||||
st.font = font.system(12)
|
||||
st.color = color.black
|
||||
st.text_alignment = :center
|
||||
|
||||
st.number_of_lines = :unlimited
|
||||
st.resize_to_fit_text
|
||||
st.size_to_fit
|
||||
end
|
||||
@@ -30,6 +30,7 @@ describe 'stylers/ui_label' do
|
||||
v.color = UIColor.blackColor
|
||||
v.textAlignment = NSTextAlignmentCenter
|
||||
v.size.width.should > 0
|
||||
v.numberOfLines.should == 0
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -54,6 +54,8 @@ describe 'subviews' do
|
||||
view.rmq_data.style_name.should == :my_style
|
||||
end
|
||||
|
||||
# TODO test ops in append, unshift, and create
|
||||
|
||||
it 'should add a subview at a specific index' do
|
||||
view = @vc.rmq.append(UIView).get
|
||||
view2 = @vc.rmq.append(UIView).get
|
||||
|
||||
Reference in New Issue
Block a user