![](/img/trans.png)
[英]IOS/Objective-C:Two images showing at same time in barbutton
[英]How to set an action for barbutton item programatically objective-c
使用以下代碼實現了一些按鈕,
UISegmentedControl *button = [[[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:@"", nil]] autorelease];
button.momentary = YES;
button.segmentedControlStyle = UISegmentedControlStyleBar;
UIBarButtonItem *barButton = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
我使用此代碼為按鈕設置了操作
[button addTarget:self
action:@selector(drawOnImageByColor:)
forControlEvents:UIControlEventTouchUpInside];
像這樣改變
[button addTarget:self
action:@selector(drawOnImageByColor:)
forControlEvents:UIControlEventValueChanged];
使用此代碼
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(drawOnImageByColor:)];
self.navigationItem.rightBarButtonItem = rightButton;
[rightButton release];
您必須設置要添加為自定義視圖的按鈕的操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.