Sizing a UILabel to fit?

I had to do this enough that I extended UILabel to do it for me: @interface UILabel (BPExtensions) – (void)sizeToFitFixedWidth:(CGFloat)fixedWidth; @end @implementation UILabel (BPExtensions) – (void)sizeToFitFixedWidth:(CGFloat)fixedWidth { self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, fixedWidth, 0); self.lineBreakMode = NSLineBreakByWordWrapping; self.numberOfLines = 0; [self sizeToFit]; } @end then to have a label to have a variable multiline height but … Read more

Persisting Cookies In An iOS Application?

You shouldn’t need to persist the cookies yourself as suggested in the other answer. NSHTTPCookieStorage will persist the cookies for you but you need to ensure that the cookies have an expiry date set on the server-side. Cookies without an expiry date are considered ‘session only’ and will get cleared when you restart the app. … Read more

Animate intrinsicContentSize changes

invalidateIntrinsicContentSize works well with animations and layoutIfNeeded. The only thing you need to consider is, that changing the intrinsic content size invalidates the layout of the superview. So this should work: [UIView animateWithDuration:0.2 animations:^{ [self invalidateIntrinsicContentSize]; [self.superview setNeedsLayout]; [self.superview layoutIfNeeded]; }];

How to get notified when scrollToRowAtIndexPath finishes animating

You can use the table view delegate’s scrollViewDidEndScrollingAnimation: method. This is because a UITableView is a subclass of UIScrollView and UITableViewDelegate conforms to UIScrollViewDelegate. In other words, a table view is a scroll view, and a table view delegate is also a scroll view delegate. So, create a scrollViewDidEndScrollingAnimation: method in your table view delegate … Read more

UIView — “user interaction enabled” false on parent but true on child?

That’s correct, userInteractionEnabled set to NO on a parent view will cascade down to all subviews. If you need some subviews to have interaction enabled, but not others, you can separate your subviews into two parent views: one with userInteractionEnabled = YES and the other NO. Then put those two parent views in the main … Read more