mirror of
https://github.com/zhigang1992/rmq.git
synced 2026-01-12 22:51:53 +08:00
Merge pull request #203 from infinitered/uilabel_resize_height
UILabel resize_height_to_fit functionality
This commit is contained in:
@@ -56,6 +56,17 @@ module RubyMotionQuery
|
|||||||
def adjusts_font_size
|
def adjusts_font_size
|
||||||
@view.adjustsFontSizeToFitWidth
|
@view.adjustsFontSizeToFitWidth
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def resize_height_to_fit
|
||||||
|
@view.lineBreakMode = UILineBreakModeWordWrap
|
||||||
|
@view.numberOfLines = 0
|
||||||
|
|
||||||
|
attributed_text = NSAttributedString.alloc.initWithString(@view.text, attributes:{NSFontAttributeName => @view.font})
|
||||||
|
rect = attributed_text.boundingRectWithSize([@view.frame.size.width, Float::MAX], options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading), context:nil)
|
||||||
|
|
||||||
|
expected_label_size = [@view.frame.size.width, rect.size.height.ceil]
|
||||||
|
@view.frame = [@view.frame.origin, expected_label_size]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -86,5 +86,58 @@ describe 'stylers/ui_label' do
|
|||||||
view.get.lineBreakMode.should == NSLineBreakByTruncatingHead
|
view.get.lineBreakMode.should == NSLineBreakByTruncatingHead
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should resize height larger when asked" do
|
||||||
|
view = @vc.rmq.append(@view_klass, :ui_label_kitchen_sink)
|
||||||
|
|
||||||
|
view.style do |st|
|
||||||
|
st.frame = {
|
||||||
|
w: 200,
|
||||||
|
h: 5
|
||||||
|
}
|
||||||
|
st.text = "Testing this thing with a really long string so that it clips but then will resize to fit properly."
|
||||||
|
end
|
||||||
|
|
||||||
|
old_size = view.get.frame.size
|
||||||
|
old_size.should == CGSizeMake(200,5)
|
||||||
|
|
||||||
|
view.style {|st| st.resize_height_to_fit}
|
||||||
|
|
||||||
|
size = view.get.frame.size
|
||||||
|
size.width.should == 200
|
||||||
|
size.height.should > 5
|
||||||
|
size.height.should < Float::MAX
|
||||||
|
|
||||||
|
# Set the height to zero and try again
|
||||||
|
view.style do |st|
|
||||||
|
st.frame = {
|
||||||
|
h: 0
|
||||||
|
}
|
||||||
|
end
|
||||||
|
view.style {|st| st.resize_height_to_fit}
|
||||||
|
view.get.frame.size.height.should > 0
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should resize height smaller when asked" do
|
||||||
|
view = @vc.rmq.append(@view_klass, :ui_label_kitchen_sink)
|
||||||
|
|
||||||
|
view.style do |st|
|
||||||
|
st.frame = {
|
||||||
|
w: 150,
|
||||||
|
h: 5000
|
||||||
|
}
|
||||||
|
st.text = "This is a small label."
|
||||||
|
end
|
||||||
|
|
||||||
|
old_size = view.get.frame.size
|
||||||
|
old_size.should == CGSizeMake(150,5000)
|
||||||
|
|
||||||
|
view.style {|st| st.resize_height_to_fit}
|
||||||
|
|
||||||
|
size = view.get.frame.size
|
||||||
|
size.width.should == 150
|
||||||
|
size.height.should < 5000
|
||||||
|
size.height.should > 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user