Skip to content

Instantly share code, notes, and snippets.

@smileyborg
smileyborg / InteractiveTransitionCollectionViewDeselection.m
Last active January 15, 2023 13:03
Animate table & collection view deselection alongside interactive transition (for iOS 11 and later)
// UICollectionView Objective-C example
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] firstObject];
if (selectedIndexPath != nil) {
id<UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator;
if (coordinator != nil) {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
@smileyborg
smileyborg / SelfSizingTableHeaderAndTableFooterViews.swift
Last active February 9, 2024 09:53
How to manually self-size UITableView tableHeaderView/tableFooterView in iOS 11
// For the best results, your tableHeaderView/tableFooterView should be a UITableViewHeaderFooterView with your content inside the contentView.
let tableHeaderView = UITableViewHeaderFooterView()
let fittingSize = CGSize(width: tableView.bounds.width - (tableView.safeAreaInsets.left + tableView.safeAreaInsets.right), height: 0)
let size = tableHeaderView.systemLayoutSizeFitting(fittingSize, withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)
tableHeaderView.frame = CGRect(origin: .zero, size: size)
tableView.tableHeaderView = tableHeaderView
// When you set this view to the tableHeaderView/tableFooterView on the table view, the table view will preserve the existing size of its frame.
// If you need to change the size, remove the tableHeaderView/tableFooterView, set a new frame on it, then re-set it on the table view again.
@sberrevoets
sberrevoets / SDCIntrinsicallySizedView
Last active August 29, 2015 13:56
UIView subclass that has a valid intrinsicContentSize based on its subviews' frames
- (CGSize)intrinsicContentSize {
__block CGFloat minX = CGFLOAT_MAX;
__block CGFloat maxX = CGFLOAT_MIN;
__block CGFloat minY = CGFLOAT_MAX;
__block CGFloat maxY = CGFLOAT_MIN;
[[self subviews] enumerateObjectsUsingBlock:^(UIView *subview, NSUInteger idx, BOOL *stop) {
// Ignore _UILayoutGuide
if (![subview conformsToProtocol:@protocol(UILayoutSupport)]) {
// We could use CGRectGet(Min|Max)(X|Y) using the subview.frame, but subview.frame is undefined when a transform is applied. This calculation is transform-friendly.
@chrisvoss
chrisvoss / PFLoadingView-Style
Created August 21, 2012 15:34
Style PFLoadingView in PFQueryTableViewController subclass
- (void)stylePFLoadingViewTheHardWay
{
UIColor *labelTextColor = [UIColor whiteColor];
UIColor *labelShadowColor = [UIColor darkGrayColor];
UIActivityIndicatorViewStyle activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
// go through all of the subviews until you find a PFLoadingView subclass
for (UIView *subview in self.view.subviews)
{
if ([subview class] == NSClassFromString(@"PFLoadingView"))