I want to display some hint to user when a user touches the button in iPhone native application, just like tooltip in web applications.
I have a large number of TextField that should be associated with info button to let the user know the detail description about the data captured in that TextField.
Can any one post steps to achieve this?
Agreed with Justin, but if you really had to:
Add an action to the UIButton that launches on the Touch Down event, e.g. UIButton * button = [[UIButton alloc] init]; [button addTarget:self action:#selector(doSomething:) forControlEvents:UIControlEventTouchDown];
Define the 'doSomething' action method as showing a custom 'tooltip' view anchored to the button location. The UIButton which was touched will be passed to the action method, from which you can access its location and so know where to anchor the tooltip.
If this all sounds laborious, check out "Is it possible to show a tooltip in an iOS app?", which links to CMPopTipView (https://github.com/chrismiles/CMPopTipView#readme), a useful package which will do it all for you. Haven't used it myself, though.
I'm not sure how to achieve this, but it sounds like a terrible User Interface idea for a mobile app.
I say that because tooltips in classic applications typically happen on mouse hover. Mobile interfaces don't have an equivalent gesture. When you touch a button, it's like a click.
If you look at most mobile applications that need to explain something to the user, it's usually done through visual elements that show up when the app loads (they'll point to different buttons, explain what they're for, and then go away after the first time the button is used).
Related
I have 3 buttons, when you click on any one of them, a corresponding UIImageView of a paper card pops up. In the interface builder the papercard is "in front" of the buttons so you can't see them when the card is visible (a good thing).
Problem is, I noticed that even though you can't see the buttons which are still behind the paper card UIImageView you still end up pressing those buttons if you click on the spot where they'd be, as though you're pressing right through the paper card.
So I need a function that will make those buttons untouchable while that paper card is visible, and remain untouchable until I hit the back button to remove the paper card and go back to the view three buttons. Is there such thing as a "disable button" code?
OK so google UIButton and you'll get to the docs here UIButton Class Reference.
Now scan the docs for anything that might work - (mmm nope)
Nope OK let's look at the superclass by following the link in the UIButton docs, which says the superclass is UIControl
Excellent there is a property called enabled - this looks like something you could use.
self.myButton.enabled = NO;
In my app i want to open a view with the content of a particular button (so that button should look clicked and should be not clickable). I have 4 button with pictures and all the four have different content inside them (Table view with different content).When this view gets open i want the first button clicked automatically and the content of that button should get displayed and by clicking any other button the content of that button should get displayed and the previous clicked button should be available to click again.
I am using different pictures for clicked and unclicked button.
Thanks,
Maybe this will help you
- (void)didClickButton:(id)sender {
UIButton *optionButton = (UIButton *)sender;
if(lastSelectedButton.tag!= optionButton.tag) {
optionButton.selected = YES;
//According to your needs enable or disable the button's interaction
}
Here lastSelectedButton should be an instance variable.
What you're describing sounds like a segmented control. Essentially the segmented control works like buttons on a tape recorder (dating myself, I know.) When you press Play, it stays down and can't be pressed again until you press Stop or FF or Rew, etc. (Ok, Stop doesn't really work that way, but the rest of the buttons do)
Unfortunately, I don't believe you can use your own images in a UISegmentedControl, but fortunately there's an open-source version that should work for you: https://github.com/xhan/PlutoLand/blob/master/PLSegmentView.h
Once you have the control in place you can change the content of your main view depending on the value of the segmented control. You can handle that in the UIControlEventValueChanged event
Keep a single selector for all the buttons something like
[btn addTarget:self action:#selector(templateSelected:) forControlEvents:UIControlEventTouchUpInside];
and make use of the tag to carry any index to the selector
[btn setTag:integer];
and if you want to keep track of previously clicked button then keep a global (id) and assign the current button address to the that id.
And if you want the first button to be clicked on load then call the function melodramatically during initialization of the first button.
[self templateSelected:firstButton];
Alright, so I have a TableView in one of my Views in my iPhone app. I'm using a UINavigationController, so using that I created the UIToolBar at the bottom of the table. Works great. However, I want the items in the toolbar to resemble how the Facebook app has them:
Not only would I like the Buttons (I will have only 2) to resemble those. (They connect when touching another button), but I really want to show the user what "Tab" they are on. In the image above, it is obvious to the user they are on the Wall. When they touch "Info", it becomes darkened and the user knows where they are. Does anyone know how they did it so my app may also have clear navigation?
What you have on a picture is standard UISegmentControl with UISegmentedControlStyleBar style - you can use it.
Just use a UISegmentedControl like they did
I was wondering what I should use to display an image on screen every time the user presses a button. I am using Objective-C/CocoaTouch on the iPod Touch. I would like to pull these images from an array I have set up and place them on the screen when the button is triggered. I feel dumb asking but any one that can point me in the right direction would be great. I think I could figure out the rest from there.
Thanks.
I'm sure there are many ways of doing this, but one way would be to define a UIImageView on the screen, and make it hidden. When the user presses the button, you can set the source of the UIImageView to the image from your array, and set the hidden property to NO.
I think it's as simple as something like this:
[myImageView setImage:[imageArray objectAtIndex:theIndex]];
In your button's action method. You can set theIndex before or afterwards to get a different image from your array every time the action method gets called.
I have a UIButton subview inside of a UITableViewCell.
When this button is touched, the user must hold the button for about a half second for the button's image to change to the UIControlStateHighlighted image.
This means that if the user just taps the button as is usually the case, the highlighted state is never shown.
Why does this occur and how can I fix it?
I just encountered this problem and saw that this issue hadn't been closed. After screwing around for a while I found a fix for it.
Now you can fix this by turning off delaysContentTouches or unchecking the "Delays content touches" box on the tableview.
The only negative side effect is that the user won't be able to tap down on a button and initiate a scrolling gesture. However, if the user tries to scroll starting from anywhere that doesn't itself accept touches, the behavior should be the same as before.
The problem is that your UIButton is inside a UITableView. This means that the table view has to determine whether your tap is going to be a swipe or if it's just a tap intended for the button. The table view has to delay sending a message to the UIButton until it knows that the user doesn't intend to swipe and therefore scroll the view instead of pressing the button.
If you don't need a table view, get rid of the UITableView.
Up for David Hodge's answer.
I just want to add a way to remove that "only negative side effect", already described by David: if you start scrolling inside a UIcontrol in a UIScrollView with delayContentTouches=NO, scrolling doesn't work.
SOLUTION
Subclass UIScrollView (or UITableView as the original question) and override:
-(BOOL) touchesShouldCancelInContentView:(UIView *)view {
return YES;
}
Your UIControls inside UIScrollView/UITableView will change their state immediately on tap and the scrollviews will be able to scroll even if the touch starts on some UIControl. Works like a charm.
I just change the image from within the target action method:
[sender setBackgroundImage:[UIImage imageNamed:#"highlighted-image.png"] forState:UIControlStateNormal];
It changes the background image instantly.
Edit: completely re-written following a misunderstanding of the question
One way of thinking of a UIButton is as a shorthand way of setting up an area of the screen that can respond to various instantaneous touch events the response it makes is defined by UIControl's Target-Action system for delivering messages to other objects.
UIControlEventTouchDown sounds like the one you need to respond to. It will be triggered as soon as someone touches inside your button - this is what the "Contact Info" button in SMS does.
UIButton* myButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect];
// SEt up title, frame etc
[myButton addTarget:self action:#selector(myButtonWasPressed) forControlEvents: UIControlEventTouchDown];
[myMainView addSubView:myButton];
Will send a -(void)myButtonWasPressed message to the object this code runs from (ideally you view controller). In myButtonWasPressed you can then add a new view or take any action you like. The SMS app pushes a view controller to display the contact info using a navigation controller.
If this still doesn't solve your problem, you're going to have to post some code in order to get more insight into what's going wrong.