ios15按钮图片背景图不要拉伸问题
2022-01-06 本文已影响0人
Johnson_9d92
原有的问题如下

解决之后

解决方案如下
self.loginButton.layer.cornerRadius = 5;
self.loginButton.clipsToBounds = YES;
//让背景图片不要拉伸
UIImage *image = _loginButton.currentBackgroundImage;
image = [image stretchableImageWithLeftCapWidth:image.size.width / 2 topCapHeight:image.size.height / 2];
[_loginButton setBackgroundImage:image forState:UIControlStateNormal];
[self.loginButton setBackgroundImage:image forState:UIControlStateHighlighted];
放在viewDidLoad调用