iPhone & UISegmentedControl - 更改图像并保留标题?

发布于 2024-10-06 20:28:15 字数 124 浏览 1 评论 0原文

有没有办法更改 uisegmentedcontrol 中所有片段的图像并保留标题?

设置图像时它会删除标题吗?或者它是否在标签顶部显示 UImageView? 如果图像位于标签顶部,是否可以访问它并将其发送到后面???

Is there any way to change the images for all segments in a uisegmentedcontrol and keep the title?

Does it remove the title when you set an image? or does it display the UImageView on top of the label?
If the image goes on top of the label is it possible to access it and send it to back???

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

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

发布评论

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

评论(3

浸婚纱 2024-10-13 20:28:15

我认为这是不可能的。该文档说明如下:

分段控件可以显示
标题(NSString 对象) 图像
(UIImage 对象)。

但是,您自己实现该控制应该相当容易。

I don't think this is possible. The documentation says the following:

A segmented control can display a
title (an NSString object) or an image
(UIImage object).

However, it should be fairly easy to implement the control yourself.

巾帼英雄 2024-10-13 20:28:15

试试这个。

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:nil];
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"up_button.png"] atIndex:0 animated:YES];
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"down_button.png"] atIndex:1 animated:YES];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
[segmentedControl setMomentary:YES];

Try this.

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:nil];
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"up_button.png"] atIndex:0 animated:YES];
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"down_button.png"] atIndex:1 animated:YES];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
[segmentedControl setMomentary:YES];
小嗷兮 2024-10-13 20:28:15

我最终循环遍历了 UISegmentedControl 中的每个 UISegment。
我向每个 UISegment 添加了一个 UIImageView 并将它们发送到视图的后面

I ended up looping through each UISegment in my UISegmentedControl.
I added a UIImageView to each UISegment and sent them to the back of the view

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