没有边框的圆角矩形 UIButton

发布于 2024-08-27 11:04:15 字数 154 浏览 5 评论 0原文

我正在尝试绘制一个普通的圆角矩形 UIButton,但没有边框。理想情况下,我希望能够更改 UIButton 上的某些设置以禁用边框。

我的问题是,如果我将按钮类型更改为“自定义”,我不会得到漂亮的蓝色选择渐变(我想保留),而且我不知道如何手动绘制它。

I'm trying to draw a normal rounded rect UIButton, but without the border. Ideally I'd like to be able to change some setting on the UIButton to disable the border.

My problem is that if I change the button type to "custom", I don't get the nice blue selection gradient (which I want to keep), and I have no idea how to draw it manually.

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

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

发布评论

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

评论(4

森罗 2024-09-03 11:04:15

将按钮类型更改为自定义。正下方有一个下拉菜单,用于“默认”、“突出显示”、“选定”等。制作蓝色渐变,将其设置为“突出显示状态配置”的图像。当你突出显示它时,它应该会给你蓝色渐变。如果您希望在选择时使用它,请使用“选定”配置。

Change the button type to custom. There's a dropdown right below that for "Default", "Highlighted", "Selected", etc. Make a blue gradient, set it as the image for the "Highlighted State Configuration". That should give you the blue gradient when you highlight it. If you want it when it's selected, use the "Selected" configuration.

゛清羽墨安 2024-09-03 11:04:15

为此,我使用了只有一个段的 UISegmentedControl。您可以使用tintColor 获得漂亮的渐变效果。事件连接略有不同,但没什么大不了的。

此答案提供了更多详细信息。

I've used a UISegmentedControl with only one segment for this. You can use tintColor you get a nice gradient. The event connections are slightly different but not a big deal.

This answer provides more detail.

雅心素梦 2024-09-03 11:04:15

您可以使用自定义类型的 UIButton。
并将适当的图像设置为 UIButton 的背景。

You can use custom type of UIButton.
And set the appropriate image as a background of the UIButton.

一笔一画续写前缘 2024-09-03 11:04:15

试试这个代码,

button.layer.borderWidth = 3;    
button.layer.borderColor = [UIColor whiteColor].CGColor;

try this code,

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