gpt4 book ai didi

ios - 如何使用 UIsegmented 控件更改背景图像

转载 作者:行者123 更新时间:2023-11-28 19:04:55 25 4
gpt4 key购买 nike

如何使用分段控件更改背景图像?

我想使用段控制更改背景图像,然后为上述过程选择该图像。

最佳答案

这是 UISegmentedControl 文档的链接.

编辑

也许我误解了你的问题。如果要更改 View 的背景图像,可以将 Controller 添加为分段控件的目标。

[segmentedControl addTarget:self action:@selector(updateBackgroundImage:) forControlEvents:UIControlEventValueChanged];

当您的控件触发 UIControlEventValueChanged 时,您可以使用这些方法中的任何一个来更改您想要的背景图像。

- (void)updateBackgroundImage:(UISegmentedControl *)sender {
self.imageView = [UIImage imageNamed:(sender.selectedSegmentIndex ? @"foo": @"bar")];
}

原始答案

正如您将在该文档中看到的那样,您可以通过不同的方式更改控件的外观。举几个例子。

-[UISegmentedControl setBackgroundImage:forState:barMetrics:]
-[UISegmentedControl dividerImageForLeftSegmentState:rightSegmentState:barMetrics:]
-[UISegmentedControl setImage:forSegmentAtIndex:]

当您的控件触发 UIControlEventValueChanged 时,您可以使用这些方法中的任何一个来更改发送者的外观。

关于ios - 如何使用 UIsegmented 控件更改背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21329427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com