Reputation: 139
I created a button and when it is clicked, it's background image changes. However the issue is when I click it , it gives a rectangle with a color.
Image:
Should Be:
I don't want to see that clicking background.
My codes are below:
let on = UIImage(named: "on") as UIImage
let off = UIImage(named: "off") as UIImage
btn.setBackgroundImage(off, forState: .Normal)
Upvotes: 2
Views: 5319
Reputation: 41
just use this
btn.setBackgroundImage(nil, forState: .Normal)
Upvotes: 3
Reputation: 23053
When you use Storyboard buttons which is IBOutlet UIButton
object. By default it is not set as a custom type. So if you set background of this button as an image, It shows border of that button with the image.
For Storyboard variables:
UIButton
control in Storyboard. Go to Attribute Inspector > Change type System to CustomSee the reference images
For programmatically created buttons:
If you create UIButton
object programmatically than set button type as UIButtonTypeCustom
.
Objective C Code:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
Swift Code:
var button = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
Upvotes: 3