Remove all constraints affecting a UIView

This approach worked for me: @interface UIView (RemoveConstraints) – (void)removeAllConstraints; @end @implementation UIView (RemoveConstraints) – (void)removeAllConstraints { UIView *superview = self.superview; while (superview != nil) { for (NSLayoutConstraint *c in superview.constraints) { if (c.firstItem == self || c.secondItem == self) { [superview removeConstraint:c]; } } superview = superview.superview; } [self removeConstraints:self.constraints]; self.translatesAutoresizingMaskIntoConstraints = YES; } … Read more

What’s the best way to add a drop shadow to my UIView

Try this: UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:view.bounds]; view.layer.masksToBounds = NO; view.layer.shadowColor = [UIColor blackColor].CGColor; view.layer.shadowOffset = CGSizeMake(0.0f, 5.0f); view.layer.shadowOpacity = 0.5f; view.layer.shadowPath = shadowPath.CGPath; First of all: The UIBezierPath used as shadowPath is crucial. If you don’t use it, you might not notice a difference at first, but the keen eye will observe a certain … Read more

CALayers didn’t get resized on its UIView’s bounds change. Why?

I used the same approach that Solin used, but there’s a typo in that code. The method should be: – (void)layoutSubviews { [super layoutSubviews]; // resize your layers based on the view’s new bounds mylayer.frame = self.bounds; } For my purposes, I always wanted the sublayer to be the full size of the parent view. … Read more

How to load a xib file in a UIView

To get an object from a xib file programatically you can use: [[NSBundle mainBundle] loadNibNamed:@”MyXibName” owner:self options:nil] which returns an array of the top level objects in the xib. So, you could do something like this: UIView *rootView = [[[NSBundle mainBundle] loadNibNamed:@”MyRootView” owner:self options:nil] objectAtIndex:0]; UIView *containerView = [[[NSBundle mainBundle] loadNibNamed:@”MyContainerView” owner:self options:nil] lastObject]; [rootView … Read more

UIView touch event in controller

You will have to add it through code. First, create the view and add it to the hierarchy: var myView = UIView(frame: CGRectMake(100, 100, 100, 100)) self.view.addSubview(myView) After that initialize gesture recognizer. Until Swift 2: let gesture = UITapGestureRecognizer(target: self, action: “someAction:”) After Swift 2: let gesture = UITapGestureRecognizer(target: self, action: #selector (self.someAction (_:))) Then … Read more

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