This file contains 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
@IBOutlet weak var constraint1: NSLayoutConstraint! | |
@IBOutlet weak var constraint2: NSLayoutConstraint! | |
@IBAction func slider1Changed(sender: AnyObject) { | |
constraint1.constant = CGFloat((sender as UISlider).value) | |
} | |
@IBAction func slider2Changed(sender: AnyObject) { | |
constraint2.constant = CGFloat((sender as UISlider).value) | |
} |
This file contains 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
@IBOutlet weak var removableView: UIView! | |
@IBAction func removeView(sender: AnyObject) { | |
removableView.removeFromSuperview() | |
} |
This file contains 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
@IBOutlet weak var constraint1: NSLayoutConstraint! | |
@IBAction func slider1Changed(sender: AnyObject) { | |
constraint1.constant = CGFloat((sender as UISlider).value) | |
} |
This file contains 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
@IBOutlet weak var constraint1: NSLayoutConstraint! | |
@IBOutlet weak var constraint2: NSLayoutConstraint! | |
@IBAction func animateViews(sender: AnyObject) { | |
constraint1.constant = CGFloat(arc4random_uniform(200)) | |
constraint2.constant = CGFloat(arc4random_uniform(200)) | |
UIView.animateWithDuration(0.5, animations: { | |
self.view.setNeedsUpdateConstraints() | |
self.view.layoutIfNeeded() |
This file contains 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
-(void)prepareLayout | |
{ | |
//don't forget to call super here | |
[super prepareLayout]; | |
/* pre-calculate and cache whatever you need here */ | |
//maybe you would want to loop over each cell like this? | |
for(NSUInteger i = 0; i < [self.collectionView numberOfSections]; i++) | |
{ |
This file contains 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
- (CGSize)collectionViewContentSize | |
{ | |
return CGSizeMake(/* calculate your width */, | |
/* calculate your height */); | |
} |
This file contains 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
-(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect | |
{ | |
NSMutableArray* elementsInRect = [NSMutableArray array]; | |
//iterate over all cells in this collection | |
for(NSUInteger i = 0; i < [self.collectionView numberOfSections]; i++) | |
{ | |
for(NSUInteger j = 0; j < [self.collectionView numberOfItemsInSection:i]; j++) | |
{ | |
//this is the cell at row j in section i |
This file contains 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
-(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
UICollectionViewLayoutAttributes* attr = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; | |
CGRect cellFrame = CGRectMake(/* calculate your origin x */, | |
/* calculate your origin y */, | |
/* calculate your width */, | |
/* calculate your height */); | |
attr.frame = cellFrame; | |
This file contains 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 MyClass { | |
lazy var myLazyProperty = ExpensiveObject() | |
} |
This file contains 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
func exampleFunc(intArg:Int) { | |
// ... | |
} | |
exampleFunc(5) //just pass the expression, no name needed |
OlderNewer