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

Subclass UIButton to add a property

Try using a category with Associative References instead. It is much cleaner and will work on all instances of UIButton. UIButton+Property.h #import <Foundation/Foundation.h> @interface UIButton(Property) @property (nonatomic, retain) NSObject *property; @end UIButton+Property.m #import “UIButton+Property.h” #import <objc/runtime.h> @implementation UIButton(Property) static char UIB_PROPERTY_KEY; @dynamic property; -(void)setProperty:(NSObject *)property { objc_setAssociatedObject(self, &UIB_PROPERTY_KEY, property, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -(NSObject*)property { return (NSObject*)objc_getAssociatedObject(self, … Read more

UIButton – text truncated

You need to use the UIButton method setTitle:forState: [self.myButton setTitle:@”Correct New Title” forState:UIControlStateNormal]; as this will correctly update the size and position of the buttons label. Where as just setting the title with self.myButton.titleLabel.text = @”Wrong New Title”; will not.

Objective C Setter overriding in Swift

In Swift the solution above worked for me, but I had to omit the Bool = true: import UIKit class CustomUIButtonForUIToolbar: UIButton { // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. override func drawRect(rect: CGRect) { // Drawing code super.drawRect(rect) self.layer.borderColor = UIColor.blueColor().CGColor self.layer.borderWidth = … Read more

UIButton in UITableViewCell

This was driving me crazy. I figured out that you need to override setHighlighted:animated: and setSelected:animated: – (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated { [super setHighlighted:highlighted animated:animated]; self.yourButton.highlighted = NO; } – (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; self.yourButton.selected = NO; // If you don’t set highlighted to NO in this method, // for some reason it’ll be highlighed … Read more

UIButton won’t gray out

There is another way without having to alpha the whole button: [startButton setTitleColor:[UIColor grayColor] forState:UIControlStateDisabled]; Then whenever you set the enabled property to NO, the button’s text will automatically gray out.

UIButton titleLabel not displaying

You always need to specify ControlState when updating button’s title! There are four possible values for UIButtons: UIControlStateNormal UIControlStateHighlighted UIControlStateDisabled UIControlStateSelected so for example: [button setTitle:@”Title” forState:UIControlStateNormal]; and then you can set custom settings for titleLabel: [button.titleLabel setFont:[UIFont fontWithName:@”Zapfino” size:20.0]]; [button.titleLabel setTextColor:[UIColor blueColor]];

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