我有一個充當開關的UIButton。 當用戶點擊它時,其狀態將變爲「已選中」並且將調用動作「一」。當用戶再次點擊UIButton狀態更改爲「未選中」並且操作不再可用時。如何通過UIAction而不觸摸UIButton
有沒有辦法通過綁在一個完全不同的UIButton設置爲「入選」的UIButton並已將其改爲「選擇」,並調用相同的動作呢?
乾杯
我有一個充當開關的UIButton。 當用戶點擊它時,其狀態將變爲「已選中」並且將調用動作「一」。當用戶再次點擊UIButton狀態更改爲「未選中」並且操作不再可用時。如何通過UIAction而不觸摸UIButton
有沒有辦法通過綁在一個完全不同的UIButton設置爲「入選」的UIButton並已將其改爲「選擇」,並調用相同的動作呢?
乾杯
當你輕觸的UIButton做出了這一點,在該按鈕的操作的操作簡單的事情,你可以將按鈕的狀態設置爲選中狀態,然後在代碼就可以調用下一行方法(動作)
- (IBAction)btn1Touched:(id)sender {
[_btn2 setSelected:YES];
[self btn2Touched:self];
}
- (IBAction)btn2Touched:(id)sender {
NSLog(@"btn Action called");
}
嘗試這樣的,」
-(IBAction)nextbutton:(id)sender{
UIButton *btn=(UIButton *)[self.view viewWithTag:tagValue];//pass tag value of that particuler button
btn.selected=YES;
//do whatevr you want.
}
從我從這個問題的理解,我想給你我的建議
if (!<your_button>.selected)
{
<your_button>.selected = YES;
// do your stuff here
}
else
{
<your_button>.selected = NO;
// do your stuff here, in your case action should be no longer available so that,
<your_button>.userInteractionEnabled = NO;
}
享受編程!
謝謝,但它實際上並不適用於我想要做的事情。 –
的UIButton已經狀態稱爲selected
,它是通過屬性selected
所以設法讓一個按鈕,選中狀態
[buttonInstance setSelected:YES];
要選它使用
[buttonInstance setSelected:NO];
請寫該按鈕動作的功能類似於,
-(void)Buttonaction
{
do your action here
also set your button has selected state.
buttonname.setselected=yes;
}
在標籤按鈕時調用此函數。
做到這一點:
-(IBAction)switchButtonClicked:(UIButton*)sender
{
if(sender.isSelected)
{
.....
}
else
{
...
}
[sender setSelected:!sender.isSelected];//This will work as Switch.
}
設置的
UIButton
Selected(Switch ON)
和default(Switch OFF)
財產(圖像和標題)從XIB
,或代碼,只要你想。 隨着一個按鈕,你可以做你的功能與此代碼
plzz給你的問題描述清楚 – Kasaname
你意味着你要調用同樣的方法將兩種不同的按鈕點擊。對? – Dilip
所以你想要像這樣僞造觸摸事件:[如何以編程方式將觸摸事件僞裝成UIButton?](http://stackoverflow.com/a/4034034/593709) –