Reputation: 931
I am trying to setup a highlighted state for keyboard buttons, but have some difficulties with it:
backgroundImage
to be beneath the spaceButton Image
, so it won't overlap shift_1
like on the image below (button is tapped).Below is my code:
[self.spaceButton setImage:[UIImage imageNamed:@"shift_1"] forState:UIControlStateNormal];
[self.spaceButton setBackgroundImage:[KeyboardViewController imageFromColor:[UIColor colorWithWhite:0.4 alpha:0.5]]
forState:UIControlStateHighlighted];
self.spaceButton.layer.cornerRadius = 7.0;
self.spaceButton.layer.masksToBounds = YES;
I would be very thankful if anyone could help me.
Upvotes: 0
Views: 69
Reputation: 1243
You would have two ways:
By Image : Just add transparent pixel at bottom,left,right in image and create new image then set that image as in background image of button.
By imageEdgeInsets
: Set button imageEdgeInsets
and use to image
property for set image(Highlighted/Normal state).
Upvotes: 1