uibutton
UIScrollview with UIButtons – how to recreate springboard?
Solution that worked for me included: Setting canCancelContentTouches in UIScrollView to YES. Extending UIScrollView to override touchesShouldCancelInContentView:(UIView *)view to return YES when view is a UIButton. According to documentation touchesShouldCancelInContentView returns “YES to cancel further touch messages to view, NO to have view continue to receive those messages. The default returned value is YES if … Read more
Can I get the element by Tag from iOS?
Use the viewWithTag method. e.g. if your button is in your controller’s view and your button’s tag is 100 the following line will return the button: UIButton *button = (UIButton *)[self.view viewWithTag:100]; EDIT: Get view with particular tag in Swift – let view = self.view.viewWithTag(100) If you want to make sure you have the specific … Read more
Stretch background image for UIButton
From the example images you provided I’m pretty sure you’re looking for UIImage‘s resizableImageWithCapInsets: UIImage *originalImage = [UIImage imageNamed:@”myImage.png”]; UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right); UIImage *stretchableImage = [originalImage resizableImageWithCapInsets:insets]; [myButton setBackgroundImage:stretchableImage forState:UIControlStateNormal]; // the image will be stretched to fill the button, if you resize it. The values in the UIEdgeInsets struct determine … Read more
UIButton with GradientLayer obscures image and darkens gradient
So I managed to get around this by doing a [button bringSubviewToFront:button.imageView] after adding the gradient. Seems that no matter what I do the new layer will add on top of the imageView, so I need to push that to the front afterwards. Objective-C: [button bringSubviewToFront:button.imageView] Swift 4.1: button.bringSubview(toFront:button.imageView!)
UIButton TouchUpInside Touch Location
UITouch *theTouch = [touches anyObject]; CGPoint where = [theTouch locationInView:self]; NSLog(@” touch at (%3.2f, %3.2f)”, where.x, where.y); That’s the right idea, except that this code is probably inside an action in your view controller, right? If so, then self refers to the view controller and not the button. You should be passing a pointer to … Read more