Is it possible to change a UIButtons background color?

This can be done programmatically by making a replica: loginButton = [UIButton buttonWithType:UIButtonTypeCustom]; [loginButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; loginButton.backgroundColor = [UIColor whiteColor]; loginButton.layer.borderColor = [UIColor blackColor].CGColor; loginButton.layer.borderWidth = 0.5f; loginButton.layer.cornerRadius = 10.0f; edit: of course, you’d have to #import <QuartzCore/QuartzCore.h> edit: to all new readers, you should also consider a few options added as “another possibility”. … Read more

How do you add an action to a button programmatically in xcode

Try this: Swift 4 myButton.addTarget(self, action: #selector(myAction), for: .touchUpInside) Objective-C [myButton addTarget:self action:@selector(myAction) forControlEvents:UIControlEventTouchUpInside]; You can find a rich source of information in Apple’s Documentation. Have a look at the UIButton’s documentation, it will reveal that UIButton is a descendant of UIControl, which implements the method to add targets. — You’ll need to pay attention … Read more

Swift – UIButton with two lines of text

There are two questions. I was wondering if it is possible to create a UIButton with two lines of text This is possible through using the storyboard or programmatically. Storyboard: Change the ‘Line Break Mode’ to Character Wrap or Word Wrap and use Alt/Option + Enter key to enter a new line in the UIButton’s … Read more

Attach parameter to button.addTarget action in Swift

You cannot pass custom parameters in addTarget:.One alternative is set the tag property of button and do work based on the tag. button.tag = 5 button.addTarget(self, action: “buttonClicked:”, forControlEvents: UIControlEvents.TouchUpInside) Or for Swift 2.2 and greater: button.tag = 5 button.addTarget(self,action:#selector(buttonClicked), forControlEvents:.TouchUpInside) Now do logic based on tag property @objc func buttonClicked(sender:UIButton) { if(sender.tag == 5){ … Read more

Is it possible to adjust x,y position for titleLabel of UIButton?

//make the buttons content appear in the top-left [button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft]; [button setContentVerticalAlignment:UIControlContentVerticalAlignmentTop]; //move text 10 pixels down and right [button setTitleEdgeInsets:UIEdgeInsetsMake(10.0f, 10.0f, 0.0f, 0.0f)]; And in Swift //make the buttons content appear in the top-left button.contentHorizontalAlignment = .Left button.contentVerticalAlignment = .Top //move text 10 pixels down and right button.titleEdgeInsets = UIEdgeInsetsMake(10.0, 10.0, 0.0, 0.0) Swift … Read more

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