我们可以更改uiSwitch上的文字

时间:2011-05-23 12:21:41

标签: objective-c uiswitch

我们可以更改UISwitch上的文本,即On&关闭。我尝试了以下代码,但崩溃了

crashLog:

  

由于未捕获异常而终止应用程序NSInvalidArgumentException,原因:' - [UISwitch setLeftLabelText:]:无法识别的选择器发送到实例0x4c65020'**

switcher = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
[switcher addTarget:self action:@selector(switchAction:)
forControlEvents:UIControlEventValueChanged];

// swit = [[UISwitch alloc] initWithFrame:CGRectZero];
[switcher setCenter:CGPointMake(160.0f,260.0f)];
[switcher setLeftLabelText: @"Female"];
[switcher setRightLabelText: @"Male"];
[[switcher rightLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]];
[[switcher leftLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]];
[[switcher leftLabel] setTextColor:[UIColor yellowColor]];

cell.accessoryView = switcher;
switcher.tag = indexPath.row;    

2 个答案:

答案 0 :(得分:5)

答案 1 :(得分:3)

看看这个:http://osiris.laya.com/projects/rcswitch/ 它允许许多自定义(包括文本)