另一个自定义 UISwitch 问题

发布于 2024-10-16 01:48:08 字数 542 浏览 7 评论 0原文

我已经查看了整个堆栈溢出,为了这个问题的答案,我只能找到适用于 4.1 及更低版本的方法,但对于 4.2.1 及更高版本,我找不到获取 ON 文本的新方法和 OFF 进行更改。有没有办法改变它说是和否。 这就是我目前所拥有的:

UISwitch *switchControl = [[UISwitch alloc] initWithFrame:frame];
    [switchControl addTarget:self action:action forControlEvents:UIControlEventValueChanged];
    switchControl.backgroundColor = [UIColor clearColor];
    switchControl.on = value;
    [cell addSubview:switchControl];
    [switchControl release];

改变 UISwitch 文本的最简单方法是什么?或者如果我制作两个图像并使用动画使它们流动会更容易,就像它是一个普通的 UISwitch 一样。

I have looked all over stack overflow, for the answer to this question, and i can only find ways which worked on 4.1 and below, but for 4.2.1 and above, i can't find a new way of getting the text of ON and OFF to change. Is there a way of changing it to say Yes and No.
This is what I have currently:

UISwitch *switchControl = [[UISwitch alloc] initWithFrame:frame];
    [switchControl addTarget:self action:action forControlEvents:UIControlEventValueChanged];
    switchControl.backgroundColor = [UIColor clearColor];
    switchControl.on = value;
    [cell addSubview:switchControl];
    [switchControl release];

What would be the easiest way of changing the text of the UISwitch? Or would it be easier if i was to make two images and using animation to make them flow, like it is a normal UISwitch.

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

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

发布评论

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

评论(1

半边脸i 2024-10-23 01:48:08

我编写了一个自定义开关类。希望这有帮助。 http://cl.ly/4OQN

编辑:
另外,也许可以尝试这个:

switchView = [[UICustomSwitch alloc] initWithFrame:CGRectZero];
[switchView setCenter:CGPointMake(160.0f,260.0f)];
[switchView setLeftLabelText: @"Foo"];
[switchView setRightLabelText: @"Bar"];
[[switchView rightLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]];
[[switchView leftLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]];
[[switchView leftLabel] setTextColor:[UIColor yellowColor]];

I wrote up a custom switch class. Hope this helps. http://cl.ly/4OQN

EDIT:
Also, maybe try this:

switchView = [[UICustomSwitch alloc] initWithFrame:CGRectZero];
[switchView setCenter:CGPointMake(160.0f,260.0f)];
[switchView setLeftLabelText: @"Foo"];
[switchView setRightLabelText: @"Bar"];
[[switchView rightLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]];
[[switchView leftLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]];
[[switchView leftLabel] setTextColor:[UIColor yellowColor]];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文