Skip to content

Instantly share code, notes, and snippets.

@james-b-kelly
james-b-kelly / CollectionViewLabelCell
Last active August 29, 2015 14:07
Multi-line UIlLabel in full-width UICollectionViewCell.
//In your UIViewController (containing the UICollectionView).
//In @interface
@property (nonatomic, strong) MyCollectionViewCellSubclass *prototypeCell;
//In viewDidLoad
//Register your subclassed cell, and load your prototype cell.
UINib *cellNib = [UINib nibWithNibName:@"MyCollectionViewCellSubclass" bundle:nil];
[collectionView registerNib:cellNib forCellWithReuseIdentifier:@"MyCollectionViewCellSubclassID"];
self.prototypeCell = [cellNib instantiateWithOwner:nil options:nil][0];
@james-b-kelly
james-b-kelly / UICollectionViewFlowLayout
Last active August 29, 2015 14:07
UICollectionViewFlowLayout
//In UICollectionViewCell subclass implementation
- (UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
layoutAttributes.size = CGSizeMake(layoutAttributes.frame.size.width, layoutAttributes.frame.size.height);
return layoutAttributes;
}
//In your view controller (containing the UICollectionView).
//In @interface
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
@james-b-kelly
james-b-kelly / gist:4bfc06eb6a52e1f48815
Created February 16, 2015 07:37
Adjust table/collection view height for keyboard.
//Set up your tableview/collection view in IB with a bottom layout constraint with an IBOutlet.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(adjustTableViewHeight:)
name:UIKeyboardDidShowNotification
object:nil];
}
- (void)adjustTableViewHeight:(NSNotification*)notification {