Last active
August 29, 2015 14:06
-
-
Save BaylorRae/5c6d8d44c13c616b2729 to your computer and use it in GitHub Desktop.
RFQuiltLayout with RubyMotion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rmq create demo | |
$ rmq create collection_view_controller images |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'motion-cocoapods' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ImagesCellStylesheet | |
- def cell_size | |
- {w: 96, h: 96} | |
- end | |
- | |
def images_cell(st) | |
- st.frame = cell_size | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ pod setup | |
$ rake pod:install |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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