Creating a reusable UIView with xib (and loading from storyboard)

Note that this QA (like many) is really just of historic interest. Nowadays For years and years now in iOS everything’s just a container view. Full tutorial here (Indeed Apple finally added Storyboard References, some time ago now, making it far easier.) Here’s a typical storyboard with container views everywhere. Everything’s a container view. It’s … Read more

How can I do Key Value Observing and get a KVO callback on a UIView’s frame?

There are usually notifications or other observable events where KVO isn’t supported. Even though the docs says ‘no’, it is ostensibly safe to observe the CALayer backing the UIView. Observing the CALayer works in practice because of its extensive use of KVO and proper accessors (instead of ivar manipulation). It’s not guaranteed to work going … Read more

UIView – How to get notified when the view is loaded?

Depending on what kind of actions you need to perform, there are several techniques: -(id)initWithFrame:(CGRect)frame – UIView’s designated initializer; always sent to a UIView to initialize it, unless the view is loaded from a nib; -(id)initWithCoder:(NSCoder *)coder – always sent to initialize a UIView whenever the view is loaded from a nib; -(void)awakeFromNib – sent … Read more

UIGestureRecognizer blocks subview for handling touch events

I had a very similar problem and found my solution in this SO question. In summary, set yourself as the delegate for your UIGestureRecognizer and then check the targeted view before allowing your recognizer to process the touch. The relevant delegate method is: – (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

resize superview after subviews change dynamically using autolayout

If you’re using Auto Layout, here’s what you need to do: Make sure you aren’t adding fixed width and/or height constraints to any of your subviews (depending on which dimension(s) you want to dynamically size). The idea is to let the intrinsic content size of each subview determine the subview’s height. UILabels come with 4 … Read more

Can UIView be copied?

this might work for you … archive the view and then unarchive it right after. This should give you a deep copy of a view: id copyOfView = [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:originalView]];

How do you draw a line programmatically from a view controller?

There are two common techniques. Using CAShapeLayer: Create a UIBezierPath (replace the coordinates with whatever you want): UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:CGPointMake(10.0, 10.0)]; [path addLineToPoint:CGPointMake(100.0, 100.0)]; Create a CAShapeLayer that uses that UIBezierPath: CAShapeLayer *shapeLayer = [CAShapeLayer layer]; shapeLayer.path = [path CGPath]; shapeLayer.strokeColor = [[UIColor blueColor] CGColor]; shapeLayer.lineWidth = 3.0; shapeLayer.fillColor = [[UIColor … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)