Skip to content

Instantly share code, notes, and snippets.

@bmichotte
Last active October 19, 2015 20:40
Show Gist options
  • Save bmichotte/54713f70fe3dae83077f to your computer and use it in GitHub Desktop.
Save bmichotte/54713f70fe3dae83077f to your computer and use it in GitHub Desktop.
class ButtonCell < PM::CollectionViewCell
def setup(data_cell, _)
super.tap do
@imageview.image = data_cell[:image].uiimage if data_cell.has_key?(:image)
@label.text = data_cell[:title] if data_cell.has_key?(:title)
end
end
def on_created
apply_style :button
@imageview = append!(UIImageView, :imageview)
@imageview.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth
@label = append!(UILabel, :label)
end
end
class HomeScreen < PM::CollectionScreen
collection_layout UICollectionViewFlowLayout,
direction: :vertical,
minimum_line_spacing: 0,
minimum_interitem_spacing: 0,
item_size: [256, 256]
cell_classes button_cell: ButtonCell
stylesheet HomeScreenStylesheet
def collection_data
[
[
{
image: 'horaire',
title: :class_schedule._,
cell_identifier: :button_cell,
action: -> {
open ScheduleScreen.new
}
},
{
image: 'jdc',
title: :timetable._,
cell_identifier: :button_cell,
action: -> {
open TimetableScreen.new
}
},
# and so on
]
]
end
def will_appear
find(UICollectionView).style do |st|
st.frame = { l: 0, t: 50, w: device.screen_width, h: device.screen_height - 50 }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment