7

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

崩溃日志:

由于未捕获的异常 NSInvalidArgumentException 而终止应用程序,原因:'-[UISwitch setLeftLabelText:]: unrecognized selector sent to instance 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;    
4

2 回答 2

5

用这个

http://www.catamount.com/blog/1063/uicustomswitch-customizing-uiswitch-color-it-change-labels/

于 2011-05-23T12:26:40.153 回答
3

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

于 2011-05-23T12:31:49.160 回答