Get button pressed id on Swift via sender

You can set a tag in the storyboard for each of the buttons. Then you can identify them this way: @IBAction func mainButton(sender: UIButton) { println(sender.tag) } EDIT: For more readability you can define an enum with values that correspond to the selected tag. So if you set tags like 0, 1, 2 for your … Read more

UIButton touch is delayed when in UIScrollView

Jeff’s solution wasn’t quite working for me, but this similar one does: http://charlesharley.com/2013/programming/uibutton-in-uitableviewcell-has-no-highlight-state In addition to overriding touchesShouldCancelInContentView in your scroll view subclass, you still need to set delaysContentTouches to false. Lastly, you need to return true rather than false for your buttons. Here’s a modified example from the above link. As commenters suggested, it … Read more

UIBarButtonItem with custom view not properly aligned on iOS 7 when used as left or right navigation bar items

Works until iOS11! You can use negative flexible spaces and rightBarButtonItems property instead of rightBarButtonItem: UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; spacer.width = -10; // for example shift right bar button to the right self.navigationItem.rightBarButtonItems = @[spacer, yourBarButton];

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 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

UITableViewCell Buttons with action

I was resolving this using a cell delegate method within UITableViewCell’s subclass. Quick overview: 1) Create a protocol protocol YourCellDelegate : class { func didPressButton(_ tag: Int) } 2) Subclass your UITableViewCell (if you haven’t done so): class YourCell : UITableViewCell { var cellDelegate: YourCellDelegate? @IBOutlet weak var btn: UIButton! // connect the button from … Read more