Updated UICollectionView template

This commit is contained in:
Todd Werth
2013-10-22 11:38:15 -07:00
parent 29f7cc1d39
commit d5be4c183f
7 changed files with 30 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
PATH
remote: .
specs:
ruby_motion_query (0.4.1b)
ruby_motion_query (0.4.1)
GEM
remote: https://rubygems.org/

View File

@@ -26,7 +26,7 @@ A fast, muggle, nonpolluting, jQuery-like library for [RubyMotion](http://rubymo
----------
**Tested only on iOS only, not OS X (nor is there any OS X specific code)**
**Tested on iOS, not OS X (nor is there any OS X specific code)**
----------
@@ -183,6 +183,8 @@ Here are the commands available to you:
> rmq create shared some_class_used_app_wide
> rmq create lib some_class_used_by_multiple_apps
> rmq create collection_view_controller foos
# To test the create command without actually creating any files, do:
> rmq create view my_view dry_run
@@ -1116,6 +1118,7 @@ Future features that I plan on adding
- add borders to UIView styler: st.borders = {l: {w: 2, color: color.black}, r: {w: 2, color: color.black}}
- add templates for: nav controller, tab controller, table controller, collection controller
- add from_right, from_bottom, and centered to both st.frame and to move
- add binding that combines KVO and events to bind an attribute of one object to the attribute of selected view(s), keeping both in sync, like so: rmq.append(UITextField).bind(@person, attr: :name, to: :text)
## Contact

View File

@@ -250,6 +250,13 @@ module RubyMotionQuery
@view.transform = CGAffineTransformMakeRotation(radians)
end
def content_mode=(value)
@view.contentMode = value
end
def content_mode
@view.contentMode
end
end
end
end

View File

@@ -1,7 +1,13 @@
class <%= @name_camel_case %>Controller < UICollectionViewController
# In app_delegate.rb or wherever you use this controller, just call #new like so:
# @window.rootViewController = <%= @name_camel_case %>Controller.new
# In app_delegate.rb or wherever you use this controller, just call .new like so:
# @window.rootViewController = <%= @name_camel_case %>Controller.new
#
# Or if you're adding using it in a navigation controller, do this
# main_controller = <%= @name_camel_case %>Controller.new
# @window.rootViewController = UINavigationController.alloc.initWithRootViewController(main_controller)
<%= @name.upcase %>_CELL_ID = "<%= @name_camel_case %>Cell"
def self.new(args = {})
# Set layout
layout = UICollectionViewFlowLayout.alloc.init
@@ -14,7 +20,7 @@ class <%= @name_camel_case %>Controller < UICollectionViewController
rmq.stylesheet = <%= @name_camel_case %>ControllerStylesheet
collectionView.tap do |cv|
cv.registerClass(<%= @name_camel_case %>Cell, forCellWithReuseIdentifier: <%= @name_camel_case %>Cell.name)
cv.registerClass(<%= @name_camel_case %>Cell, forCellWithReuseIdentifier: <%= @name.upcase %>_CELL_ID)
cv.delegate = self
cv.dataSource = self
cv.allowsSelection = true
@@ -30,7 +36,7 @@ class <%= @name_camel_case %>Controller < UICollectionViewController
# Remove if you are only supporting portrait
def willAnimateRotationToInterfaceOrientation(orientation, duration: duration)
rmq.all.reapply_styles
rmq(:reapply_style).reapply_styles
end
def numberOfSectionsInCollectionView(view)
@@ -38,11 +44,11 @@ class <%= @name_camel_case %>Controller < UICollectionViewController
end
def collectionView(view, numberOfItemsInSection: section)
40
200
end
def collectionView(view, cellForItemAtIndexPath: index_path)
view.dequeueReusableCellWithReuseIdentifier(<%= @name_camel_case %>Cell.name, forIndexPath: index_path).tap do |cell|
view.dequeueReusableCellWithReuseIdentifier(<%= @name.upcase %>_CELL_ID, forIndexPath: index_path).tap do |cell|
cell.setup_with(rmq)
# Update cell's data here
@@ -50,7 +56,8 @@ class <%= @name_camel_case %>Controller < UICollectionViewController
end
def collectionView(view, didSelectItemAtIndexPath: index_path)
cell = collectionView.cellForItemAtIndexPath(index_path)
cell = view.cellForItemAtIndexPath(index_path)
puts "Selected at section: #{index_path.section}, row: #{index_path.row}"
end
end

View File

@@ -10,12 +10,12 @@ class <%= @name_camel_case %>ControllerStylesheet < ApplicationStylesheet
end
def collection_view(st)
st.frame = :full
st.view.contentInset = [@margin, @margin, @margin, @margin]
st.background_color = color.white
st.view.collectionViewLayout.tap do |cl|
cl.itemSize = cell_size
#cl.scrollDirection = UICollectionViewScrollDirectionHorizontal
#cl.headerReferenceSize = cell_size
cl.minimumInteritemSpacing = @margin
cl.minimumLineSpacing = @margin

View File

@@ -1,23 +1,17 @@
class <%= @name_camel_case %>Cell < UICollectionViewCell
def setup_with(controller_rmq)
unless @initialized
@initialized = true
controller_rmq.wrap(self).tap do |q|
q.apply_style :<%= @name %>_cell
# Add your subviews, init stuff here
# @foo = q.append(UILabel, :foo).get
end
@initialized = true
end
end
def prepareForReuse
end
def select
end
def deselect
end
end

View File

@@ -17,7 +17,7 @@ end
# To style this view include its stylesheet at the top of each controller's
# stylesheet that is going to use it:
# class SomeStylesheet < ApplicationStylesheet
# include <%= @stylesheet_name %>
# include <%= @name_camel_case %>Stylesheet
# Another option is to use your controller's stylesheet to style this view. This
# works well if only one controller uses it. If you do that, delete the