ios - 设置 UIButton 背景的 alpha 但不是标题

标签 ios xcode uibutton

当我设置按钮的 alpha 时,它也会影响标题的不透明度。有没有办法只定位背景并将标题 alpha 保留为 1.0?

最佳答案

这对我有用:

self.myButton.backgroundColor = [UIColor clearColor];

或者如果你不想让它完全清晰,但仍然可以使用:

self.myButton.backgroundColor = [UIColor colorWithRed:200.0/255.0 green:200.0/255.0 blue:200.0/255.0 alpha:0.5];

第二个示例将为您提供 alpha 0.5 的灰色。

SWIFT 4 更新

myButton.backgroundColor = .clear

myButton.backgroundColor = UIColor(red: 200.0/255.0, green: 200.0/255.0, blue: 200.0/255.0, alpha:0.5)

关于ios - 设置 UIButton 背景的 alpha 但不是标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17492840/

相关文章:

ios - 如何从子数组对象中检索属性值?

xcode - 每次关闭应用程序时都会播放本地通知

ios - UIButton 上的 UILongPressGestureRecognizer 不起作用

ios - 第一个 UIButton 触发同一 View 的另一个 UIbutton 事件

ios - UIButton:为什么圆角可见?

iphone - 从动态生成的文本字段中获取 textfield.text 值

ios - 将 tableview 行标题传递给 viewcontroller swift

iphone - 如何使用 OpenGL ES 2.0 应用光源?

ios - * 由于未捕获的异常 'NSInternalInconsistencyException' 在 iOS 中终止应用程序

jquery - 使用 UIButton 在 UIWebView 中切换 DIV?