diff --git a/motion/ruby_motion_query/stylers/ui_label_styler.rb b/motion/ruby_motion_query/stylers/ui_label_styler.rb index 57388e1..392fb67 100644 --- a/motion/ruby_motion_query/stylers/ui_label_styler.rb +++ b/motion/ruby_motion_query/stylers/ui_label_styler.rb @@ -29,7 +29,7 @@ module RubyMotionQuery end def line_break_mode=(value) - @view.lineBreakMode = value + @view.lineBreakMode = LINE_BREAK_MODES[value] || value end def line_break_mode @view.lineBreakMode diff --git a/motion/ruby_motion_query/stylers/ui_view_styler.rb b/motion/ruby_motion_query/stylers/ui_view_styler.rb index cd178ce..048cf97 100644 --- a/motion/ruby_motion_query/stylers/ui_view_styler.rb +++ b/motion/ruby_motion_query/stylers/ui_view_styler.rb @@ -61,6 +61,17 @@ module RubyMotionQuery always: UITextFieldViewModeAlways } + LINE_BREAK_MODES = { + word_wrapping: NSLineBreakByWordWrapping, + word_wrap: NSLineBreakByWordWrapping, + char_wrapping: NSLineBreakByCharWrapping, + char_wrap: NSLineBreakByCharWrapping, + clipping: NSLineBreakByClipping, + truncating_head: NSLineBreakByTruncatingHead, + truncating_tail: NSLineBreakByTruncatingTail, + truncating_middle: NSLineBreakByTruncatingMiddle + } + AUTO_CORRECTION_TYPES = { default: UITextAutocorrectionTypeDefault, no: UITextAutocorrectionTypeNo, diff --git a/spec/stylers/ui_label_styler.rb b/spec/stylers/ui_label_styler.rb index 7c6edbc..2d9c902 100644 --- a/spec/stylers/ui_label_styler.rb +++ b/spec/stylers/ui_label_styler.rb @@ -9,7 +9,7 @@ class StyleSheetForUIViewStylerTests < RubyMotionQuery::Stylesheet st.adjusts_font_size = true st.resize_to_fit_text st.size_to_fit - st.line_break_mode = NSLineBreakByWordWrapping + st.line_break_mode = :word_wrapping end def ui_label_color(st) @@ -71,5 +71,20 @@ describe 'stylers/ui_label' do v.text.should == 'RMQ' end end + + it "allows setting line_break_mode to a symbol or constant" do + view = @vc.rmq.append(@view_klass, :ui_label_attributed_string) + + view.style do |st| + st.line_break_mode = :char_wrapping + end + view.get.lineBreakMode.should == NSLineBreakByCharWrapping + + view.style do |st| + st.line_break_mode = NSLineBreakByTruncatingHead + end + view.get.lineBreakMode.should == NSLineBreakByTruncatingHead + + end end