iphone - 根据状态修改 UIButtons 层

标签 iphone ios uibutton calayer rounded-corners

我有一个背景 UI 图像,每当我触摸 UIButton 时就会显示该图像:

[btn setImage:[UIImage imageNamed:@"background.png"] forState:UIControlStateNormal];

我还修改了 uibutton 的图层,使其圆角

[btn.layer setCornerRadius:10];

这可行,但角半径未用于背景图像。我可以在

访问图像
[btn backgroundImageForState:UIControlEventTouchDown]

但因为这是一个 UIImage,所以它不会有 CA 层

我想要的是 CALayer 也支持背景图像,或者至少应该支持圆角。

最佳答案

我猜你需要将 masksToBounds 设置为 YES:

btn.layer.masksToBounds = YES;

关于iphone - 根据状态修改 UIButtons 层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10106948/

相关文章:

ios - 在约束调整大小后获取 imageview 边界

iOS:使用另一个类中定义的 UITableViewCell 中按钮的选定状态填充数组

ios - 多个 UIButtons 只能选择一个 - swift 中的子类

iphone - 无法识别的选择器已发送到UIRefreshControl

iphone - 是否有任何工具可以在 iPhone 和黑莓移动应用程序中自动编写测试用例?

objective-c - 为什么我的字符串在我的 iOS 应用程序中可能不安全?

ios - 如何使用 Swift (Xcode) 将数组添加到 firebase

ios - 当我将 AVCaptureVideoPreviewLayer 添加到我的 UIView 时,UIButton 消失了

iphone - 测量来自iPhone的声音输入

ios - 推送通知 Firebase 导致崩溃