UIButton events. What’s the difference?

From Apple’s doc for UIControlEvents: UIControlEventTouchCancel A system event canceling the current touches for the control. UIControlEventTouchDown A touch-down event in the control. UIControlEventTouchDownRepeat A repeated touch-down event in the control; for this event the value of the UITouch tapCount method is greater than one. UIControlEventTouchDragEnter An event where a finger is dragged into the … Read more

iOS 7 round framed button

You can manipulate the CALayer of your button to do this pretty easily. // assuming you have a UIButton or more generally a UIView called buyButton buyButton.layer.cornerRadius = 2; buyButton.layer.borderWidth = 1; buyButton.layer.borderColor = [UIColor blueColor].CGColor; // (note – may prefer to use the tintColor of the control) you can tweak each of those to … Read more

How to add a drop shadow to a UIButton?

There is only one tiny mistake in the question that causes the shadow to not be displayed: masksToBounds:YES also masks the shadow! Here’s the correct code: self.layer.cornerRadius = 8.0f; self.layer.masksToBounds = NO; self.layer.borderWidth = 1.0f; self.layer.shadowColor = [UIColor greenColor].CGColor; self.layer.shadowOpacity = 0.8; self.layer.shadowRadius = 12; self.layer.shadowOffset = CGSizeMake(12.0f, 12.0f); Unfortunately, this means we cannot mask … Read more

Left-align image and center text on UIButton

This solution works with Swift 3 and respects original content and image edge insets while keeping the title label always centered in the available space, which makes much easier adjusting margins. It overrides titleRect(forContentRect:) method and returns the correct frame: @IBDesignable class LeftAlignedIconButton: UIButton { override func titleRect(forContentRect contentRect: CGRect) -> CGRect { let titleRect … Read more

Setting up buttons in SKScene

you could use a SKSpriteNode as your button, and then when the user touches, check if that was the node touched. Use the SKSpriteNode’s name property to identify the node: //fire button – (SKSpriteNode *)fireButtonNode { SKSpriteNode *fireNode = [SKSpriteNode spriteNodeWithImageNamed:@”fireButton.png”]; fireNode.position = CGPointMake(fireButtonX,fireButtonY); fireNode.name = @”fireButtonNode”;//how the node is identified later fireNode.zPosition = 1.0; … Read more

How do I scale a UIButton’s imageView?

For the original poster, here is the solution I found: commentButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill; This will allow your button to scale horizontally. There is a vertical setting as well. Took me several hours to figure that one out (the naming of the property is very unintuitive) so figured I’d share.

Change UIButton BorderColor in Storyboard

For Swift: Swift 3: extension UIView { @IBInspectable var cornerRadius: CGFloat { get { return layer.cornerRadius } set { layer.cornerRadius = newValue layer.masksToBounds = newValue > 0 } } @IBInspectable var borderWidth: CGFloat { get { return layer.borderWidth } set { layer.borderWidth = newValue } } @IBInspectable var borderColor: UIColor? { get { return UIColor(cgColor: … Read more

How can I init a UIButton subclass?

With Swift 3, according to your needs, you may choose one of the seven following code snippets to solve your problem. 1. Create your UIButton subclass with a custom initializer This solution allows you to create instances of your UIButton subclass with the appropriate value for your property. With this solution, you can only create … Read more

How to add 2 buttons into the UINavigationbar on the right side without IB?

With iOS 5+ it’s as easy as: UIBarButtonItem *btnShare = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(share)]; UIBarButtonItem *btnRefresh = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh)]; [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:btnShare, btnRefresh, nil]];

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