简体   繁体   中英

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.

在此处输入图片说明

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM