以编程方式设置 UIButton 的按钮类型

发布于 2024-09-06 12:28:35 字数 177 浏览 8 评论 0原文

我在 IB 中添加了一个 UIButton,但是此按钮后面的视图会更改颜色,我需要在 InfoDarkInfoLight< 之间切换按钮的类型/em>.但奇怪的是,buttonType 属性是只读的。那么如何在明暗信息按钮之间切换呢?

I have a UIButton which I've added in IB, however the view behind this button changes color and I need to switch the button's type between InfoDark and InfoLight. Bizarrely though, buttonType property is read only. So how can i switch between light and dark info buttons?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

妳是的陽光 2024-09-13 12:28:35

您无法设置 buttonType readonly 属性,使用以下内容可能会有所帮助:

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

You can't set buttonType readonly property, use below may help:

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
飘逸的'云 2024-09-13 12:28:35

.buttonType 一旦设置,就无法更改。

您可以准备两个按钮,并根据背景颜色隐藏其中一个。

There's no way to change the .buttonType once it's set.

You can prepare two buttons, and hide one of them depending on the background color.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文