Sha256: 5e6fb201e6e24333042f71705bf4319c700f0129af00019da42be73cc596f30b
Contents?: true
Size: 1.31 KB
Versions: 5
Compression:
Stored size: 1.31 KB
Contents
# Methods to retrieve a subview using the stylename as a key # Kinda similar to jQuery-style $().find('stylename') class UIView # get one subview by stylename or class # my_view.viewWithStylename :button => #<UIButton..> # my_view.viewWithStylename UIButton => #<UIButton..> def viewWithStylename name_or_class if name_or_class.is_a? Class view = subviews.find { |view| view.is_a? name_or_class } else view = subviews.find { |view| view.stylename == name_or_class } end return view if view # found_subview will get assigned to the view we want, but the subview is # what is returned. found_subview = nil view = subviews.find {|subview| found_subview = subview.viewWithStylename(name_or_class) } return found_subview if view nil # couldn't find it end # get all subviews by stylename or class # my_view.viewsWithStylename :button => [#<UIButton..>, #<UIButton...>] # my_view.viewsWithStylename UIButton => [#<UIButton..>, #<UIButton...>] def viewsWithStylename name_or_class r = [] subviews.each do |view| if name_or_class.is_a? Class if view.is_a? name_or_class r << view end elsif view.stylename == name_or_class r << view end r.concat view.viewsWithStylename name_or_class end r end end
Version data entries
5 entries across 5 versions & 1 rubygems