How to change the background color of a UIButton while it’s highlighted?

At some point in my app I have a highlighted UIButton (for example when a user has his finger on the button) and I need to change the background color while the button is highlighted (so while the finger of the user is still on the button). I tried the following: _button.backgroundColor = [UIColor redColor]; … Read more

How do you add multi-line text to a UIButton?

I have the following code… UILabel *buttonLabel = [[UILabel alloc] initWithFrame:targetButton.bounds]; buttonLabel.text = @”Long text string”; [targetButton addSubview:buttonLabel]; [targetButton bringSubviewToFront:buttonLabel]; …the idea being that I can have multi-line text for the button, but the text is always obscured by the backgroundImage of the UIButton. A logging call to show the subviews of the button shows … Read more

How can I set the title of a UIButton as left-aligned?

I need to display an email address on the left side of a UIButton, but it is being positioned to the centre. Is there any way to set the alignment to the left side of a UIButton? This is my current code: UIButton* emailBtn = [[UIButton alloc] initWithFrame:CGRectMake(5,30,250,height+15)]; emailBtn.backgroundColor = [UIColor clearColor]; [emailBtn setTitle:obj2.customerEmail forState:UIControlStateNormal]; … Read more