Skip to content

Instantly share code, notes, and snippets.

@BaylorRae
Last active August 29, 2015 14:06
Show Gist options
  • Save BaylorRae/5c6d8d44c13c616b2729 to your computer and use it in GitHub Desktop.
Save BaylorRae/5c6d8d44c13c616b2729 to your computer and use it in GitHub Desktop.
RFQuiltLayout with RubyMotion
def collectionView(view, numberOfItemsInSection: section)
boxes.length
end
def boxes
@boxes ||= 200.times.map do |n|
{
height: [1,2,3].sample,
label: n
}
end
end
#...
# RFQuiltLayoutDelegate methods
def blockSizeForItemAtIndexPath(index_path)
box = boxes[index_path.row]
CGSizeMake(1, box[:height])
end
def insetsForItemAtIndexPath(index_path)
UIEdgeInsetsMake(2, 2, 2, 2)
end
class ImagesController < UICollectionViewController
#...
def self.new(args = {})
# use RFQuiltLayout for collection view
layout = RFQuiltLayout.alloc.init
self.alloc.initWithCollectionViewLayout(layout)
end
def viewDidLoad
#...
# set the layout's delegate
layout = collectionView.collectionViewLayout
layout.delegate = self
layout.blockPixels = CGSizeMake(75, 75)
end
# RFQuiltLayoutDelegate methods
def blockSizeForItemAtIndexPath(index_path)
CGSizeMake(1, 2)
end
def insetsForItemAtIndexPath(index_path)
UIEdgeInsetsMake(2, 2, 2, 2)
end
#...
end
$ rmq create demo
$ rmq create collection_view_controller images
gem 'motion-cocoapods'
module ImagesCellStylesheet
- def cell_size
- {w: 96, h: 96}
- end
-
def images_cell(st)
- st.frame = cell_size
end
module ImagesControllerStylesheet
def collection_view(st)
- st.view.contentInset = [@margin, @margin, @margin, @margin]
st.background_color = color.white
-
- st.view.collectionViewLayout.tap do |cl|
- cl.itemSize = [cell_size[:w], cell_size[:h]]
- #cl.scrollDirection = UICollectionViewScrollDirectionHorizontal
- #cl.headerReferenceSize = [cell_size[:w], cell_size[:h]]
- cl.minimumInteritemSpacing = @margin
- cl.minimumLineSpacing = @margin
- #cl.sectionInset = [0,0,0,0]
- end
end
$ pod setup
$ rake pod:install
app.pods do
pod 'RFQuiltLayout', '~> 1.1.1'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment