How to change UIButton image in Swift

From your Obc-C code I think you want to set an Image for button so try this way: let playButton = UIButton(type: .Custom) if let image = UIImage(named: “play.png”) { playButton.setImage(image, forState: .Normal) } In Short: playButton.setImage(UIImage(named: “play.png”), forState: UIControlState.Normal) For Swift 3: let playButton = UIButton(type: .custom) playButton.setImage(UIImage(named: “play.png”), for: .normal)

iOS: UIButton resize according to text length

In UIKit, there are additions to the NSString class to get from a given NSString object the size it’ll take up when rendered in a certain font. Docs was here. Now it’s here under Deprecated. In short, if you go: CGSize stringsize = [myString sizeWithFont:[UIFont systemFontOfSize:14]]; //or whatever font you’re using [button setFrame:CGRectMake(10,0,stringsize.width, stringsize.height)]; …you’ll … Read more

Get button click inside UITableViewCell

1) In your cellForRowAtIndexPath: method, assign button tag as index: cell.yourbutton.tag = indexPath.row; 2) Add target and action for your button as below: [cell.yourbutton addTarget:self action:@selector(yourButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; 3) Code actions based on index as below in ViewControler: -(void)yourButtonClicked:(UIButton*)sender { if (sender.tag == 0) { // Your code here } } Updates for multiple Section: You … Read more

How to make UIButton’s text alignment center? Using IB

This will make exactly what you were expecting: Objective-C: [myButton.titleLabel setTextAlignment:UITextAlignmentCenter]; For iOS 6 or higher it’s [myButton.titleLabel setTextAlignment: NSTextAlignmentCenter]; as explained in tyler53’s answer Swift: myButton.titleLabel?.textAlignment = NSTextAlignment.Center Swift 4.x and above myButton.titleLabel?.textAlignment = .center

UIButton Image + Text IOS

I see very complicated answers, all of them using code. However, if you are using Interface Builder, there is a very easy way to do this: Select the button and set a title and an image. Note that if you set the background instead of the image then the image will be resized if it … Read more

Make a UIButton programmatically in Swift

You’re just missing the colon at the end of the selector name. Since pressed takes a parameter the colon must be there. Also your pressed function shouldn’t be nested inside viewDidLoad. override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let myFirstLabel = UILabel() let myFirstButton … Read more

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