Edgar
Edgar

Reputation: 931

Custom keyboard buttons iOS

I am trying to setup a highlighted state for keyboard buttons, but have some difficulties with it:

  1. I can't set backgroundImage to be beneath the spaceButton Image, so it won't overlap shift_1 like on the image below (button is tapped).
  2. I can't set up layer margins, so that there would be a space from the bottom and other buttons, and at the same time that spacing would function as that button.

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.

enter image description here

Upvotes: 0

Views: 69

Answers (1)

virus
virus

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

Related Questions