CGRect buttonFrame = CGRectMake(10, 80, 100, 30);
UIButton *button = [[UIButton alloc] initWithFrame: buttonFrame];
[button setTitle: @"Start" forState: UIControlStateNormal];
[button addTarget:self action:@selector(start_Accel) forControlEvents:UIControlEventTouchUpInside];
[button setTitle: @"Stop" forState: UIControlEventTouchUpInside];
[button addTarget:self action:@selector(stop_Accel) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:button];
我想創建一個按鈕,可以在用戶按下時啓動和停止加速度計更新,但它的標題也應該從開始到停止更改,並且它應該繼續,直到用戶通過anoterh按鈕重置所有內容,但我有除了下面的代碼,沒有想法完成它,但它不會改變標題並呼叫停止操作?創建一個可以觸發兩個動作並更改標題的按鈕?
預先感謝您!
謝謝你的回答,在這種情況下,我可以改變按鈕的文字?我需要在.h中定義按鈕@property(保留)IBOutlet UIButton * someButton; 然後使用[somebutton setTitle:@「Start」forState:UIControlStateNormal]; – sam
是的,這是正確的! – Pfitz
嗨。我可以知道你爲什麼用@synthesize startStopButtonIsActive = _startStopButtonIsActive編輯你的答案的原因; 也是我能夠實現代碼來改變標題,謝謝! – sam