UICollectionView spacing margins

You can use the collectionView:layout:insetForSectionAtIndex: method for your UICollectionView or set the sectionInset property of the UICollectionViewFlowLayout object attached to your UICollectionView: – (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{ return UIEdgeInsetsMake(top, left, bottom, right); } or UICollectionViewFlowLayout *aFlowLayout = [[UICollectionViewFlowLayout alloc] init]; [aFlowLayout setSectionInset:UIEdgeInsetsMake(top, left, bottom, right)]; Updated for Swift 5 func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: … Read more

UIView’s frame, bounds, center, origin, when to use what?

Marco’s answer above is correct, but just to expand on the question of “under what context”… frame – this is the property you most often use for normal iPhone applications. most controls will be laid out relative to the “containing” control so the frame.origin will directly correspond to where the control needs to display, and … Read more

Multiline label in UIStackView

The correct answer is here: https://stackoverflow.com/a/43110590/566360 Embed the UILabel inside a UIView (Editor -> Embed In -> View) Use constraints to fit the UILabel to the UIView (for example, trailing space, top space, and leading space to superview constraints) The UIStackView will stretch out the UIView to fit properly, and the UIView will constrain the … Read more

Disable the interactive dismissal of presented view controller

Option 1: viewController.isModalInPresentation = true (Disabled interactive .pageSheet dismissal acts like this.) Since the iOS 13, UIViewController contains a new property called isModalInPresentation which must be set to true to prevent the interactive dismissal. It basically ignores events outside the view controller’s bounds. Bear that in mind if you are using not only the automatic … Read more

Is it possible to disable floating headers in UITableView with UITableViewStylePlain?

A probably easier way to achieve this: Objective-C: CGFloat dummyViewHeight = 40; UIView *dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, dummyViewHeight)]; self.tableView.tableHeaderView = dummyView; self.tableView.contentInset = UIEdgeInsetsMake(-dummyViewHeight, 0, 0, 0); Swift: let dummyViewHeight = CGFloat(40) self.tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: self.tableView.bounds.size.width, height: dummyViewHeight)) self.tableView.contentInset = UIEdgeInsets(top: -dummyViewHeight, left: 0, bottom: 0, right: … Read more

How to use UIVisualEffectView to Blur Image?

Just put this blur view on the imageView. Here is an example in Objective-C: UIVisualEffect *blurEffect; blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; UIVisualEffectView *visualEffectView; visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; visualEffectView.frame = imageView.bounds; [imageView addSubview:visualEffectView]; and Swift: var visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light)) visualEffectView.frame = imageView.bounds imageView.addSubview(visualEffectView)

How to change Navigation Bar color in iOS 7?

The behavior of tintColor for bars has changed in iOS 7.0. It no longer affects the bar’s background. From the documentation: barTintColor Class Reference The tint color to apply to the navigation bar background. @property(nonatomic, retain) UIColor *barTintColor Discussion This color is made translucent by default unless you set the translucent property to NO. Availability … Read more

CGRectMake, CGPointMake, CGSizeMake, CGRectZero, CGPointZero is unavailable in Swift

CGRect Can be simply created using an instance of a CGPoint or CGSize, thats given below. let rect = CGRect(origin: CGPoint(x: 0,y :0), size: CGSize(width: 100, height: 100)) // Or let rect = CGRect(origin: .zero, size: CGSize(width: 100, height: 100)) Or if we want to specify each value in CGFloat or Double or Int, we … Read more