目標是在UIButton單擊時更改我的UITextView的字體顏色和背景顏色,然後在再次單擊UIButton時將它們還原爲原始顏色;然後重複,等等。更改UIButton按鈕上的現有設置UIColors按
默認顏色設置
- 文字:
blackColor
- 背景:
lightGrayColor
在按鈕點擊(改變..)
- 文字:
greenColor
- 背景:
blackColor
(這時如果再次點擊,變回默認的顏色設置)
到目前爲止,我有這樣的:
- (IBAction) enableSleepMode:(id)sender {
[txtNotes setTextColor:[UIColor greenColor]];
[txtNotes setBackgroundColor:[UIColor blackColor]];
}
我道歉,我不確定該從哪裏出發。提前致謝。
恰好是不工作怎麼辦?該代碼似乎將它的工作設置爲綠色/黑色?你可以做一個'if(txtNotes.textColor == [UIColor greenColor])'來確定它的進入和交換的狀態... – Shizam 2013-02-15 20:26:58