使用下面的代码
实现了一些barbuttonsUISegmentedControl *button = [[[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:@"", nil]] autorelease];
button.momentary = YES;
button.segmentedControlStyle = UISegmentedControlStyleBar;
UIBarButtonItem *barButton = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
我使用此代码
为按钮设置了set动作[button addTarget:self
action:@selector(drawOnImageByColor:)
forControlEvents:UIControlEventTouchUpInside];
答案 0 :(得分:4)
像这样改变
[button addTarget:self
action:@selector(drawOnImageByColor:)
forControlEvents:UIControlEventValueChanged];
答案 1 :(得分:2)
使用此代码
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(drawOnImageByColor:)];
self.navigationItem.rightBarButtonItem = rightButton;
[rightButton release];
答案 2 :(得分:1)
您必须将要添加的按钮的操作设置为自定义视图。