how to check is a button still pressed (clicked) or not? - iphone

I need to know the state of the button at this time if clicked or not ?
thanks

if (myButton.state & UIControlStateHighlighted) {
// Do your stuff the user is currently holding down her finger…
}

take a look at the state property of your UIButton. You're interested in UIControlStateHighlighted.

Related

How to make IBAction do nothing until button pressed?

I am making a swift program that rolls die when a button is tapped but before that it asks them if they believe they will roll snake eyes, yes or no.
I want to know if its possible that when yes or no is tapped it will wait for the user to tap the roll button and then execute a response based on that? I am confused on how to add an IBAction pressed.
I have tried to add the yes button IBAction into the roll button IBAction and have ended up with many errors.
#IBAction func yesButton(_ sender: Any) {
if(diceImageView1.image == diceImageView2.image){
resultText()
} else {
lossText()
//functions changes label to message telling user if they rolled snake eyes or not
}
}
I expect the user to be able to tap a response and then have to tap the roll button for the label to change.
Present a UIAlertViewController. Then do logic depending on the button.
See guide
https://medium.com/ios-os-x-development/how-to-use-uialertcontroller-in-swift-70143d7fbede

How to set action for UILocalNotification "CLOSE" button?

How to set action for UILocalNotification "CLOSE" action? If the user click the "CLOSE" button, at the time I will stop the audio player. Is it possible to do this?
I need some suggestions about this feature.
Please help me. Thanks in advance.
You can't detect the close or view button on an UILocalNotification because the notification is handled by iOS and not your app.
If the user decides to view the notification, your app will be started or brought to the foreground and then your app will receive the notification that the user used to open the app.
No, it is not possible to do this. We don't get any event for this.
Yes it is possible you need to create on delegate method and in that method you need to stop your audio player or else when you are calling close button action at that time you need to stop your audio player.

How to store a string value in button(cannot use tags.)

I am creating a button. I need to store a string value in the button. I am not supposed to use tag in this case. But when, I am tapping the button I need the data stored in the button. How can I do this?
You could subclass the button class to add a new public property that stores the data you need. Check out this answer, too.
When you are tapping the button, send a sender . like
-(IBAction)whenTapping:(id)sender{
sender.text; //you needed.
}

How to display only one button on UILocalNotification

I have implemented UILocalNotification. Everything is working fine and i can see the Notification also. I can see the notification and it shows me two button "cancel" and "View" from which i do not want "view" button can i do this?
How to do this?
Hi sorry for late reply you can Have only Ok button for UilocalNotifications
by doing this
notif.hasAction=NO;
by doing this you cannot see view button in the notifications Hope it solved your Problem
No. you can not do this. because local notification generated from ios u only change the name of view button by alertAction property.
i think its not possible to show one button in nslocal notification
notification.alertAction = NSLocalizedString(#"hello", nil); // its set instead of view to hello.
notification.alertAction = NSLocalizedString(nil, nil); // default view Name is coming For action Button to application

Need something other than touchup inside

I have a button in my iphone app, when I click the button it calls a linked method, that I have done as:
[myButton addTarget:self action:#selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
all working well, but i want if user tap the button for say 5 second continuously then he will be shown a message that will be there and gone away after some time and button does not get clicked, how can I do that, please help me.
Many Thanks in advance.
Regards
iPhone Developer11
Youcould use UIControlEventTouchDown and make sure it is touched down in the right view and if it is start a timer. If there are no UIControlEventTouchUpInside for 5 seconds you do whatever you need to do.
You should check docs for UILongPressGestureRecognizer. I think it fits your requirements.