UISlider highlited property for showing the value. - iphone

i have IBOutlet uislider. i want it to show the value of slider when the user presses the slider and change the value of it when the user take his hand off the slider i want it to disapper. So when the user touches to change the value of slider the label shows the value and when the user take his finger of the slider the label automaticly disapper.
My code is:
-(IBAction)sliderSlide:(UISlider *)aSlider {
float f=slider.value;
NSString *show=[NSString stringWithFormat:#"%.2f %%",f];
label2.text=show;
}
i know i need to use slider.highlited=YES; but where and how can i turn it back to hidden?

- (IBAction)touchEndedAction
{
self.label2.hidden = YES;
}
set the IBAction to the sliders UIControlEventEditingDidEnd or UIControlEventTouchCancel
try it out.

UIControlEventEditingDidEnd didn't work for me, but UIControlEventTouchDown works

Related

stepper work only pressed by twice?

I an using a stepper to control the font size of a text view, but there is no action being fired until I press the stepper twice. Why is this happening?
The following code is for the `mystepper' IBAction:
- (IBAction) changeFontSize:(id)sender
{
[myStepper setMinimumValue:14.0]
self.myStepper.maximumValue =20.0;
CGFloat newSize = [myTextView fontWithSize:self.stepper.value];
self.myTextView.font = newSize;
}
Check whether u had connected the UIStepper Recieved Actions to the changeFontSize: function for Values Changed not for Touches inside

How to release user touch on UISlider?

I have such a problem... I want to block user's slider when he is sliding. I thought .isUserInteractionEnabled will handle that but it works only after the user releases slider.
I would like to 'steal' the slider from user and stop it.
How to do that?
You should add a selector to your UISlider object. For instance, if you had a UISlider named "slider" you should do this:
[slider addTarget:self action:#selector(sliderMoved:) forControlEvents:UIControlEventValueChanged];
//runs a method called "sliderMoved" located in the same class as the slider (hence the addTarget:self) when the value is changed of the slider
and then you could make a method like this, which sets the value at the average whenever the user tries to slide the slider:
-(void)sliderMoved:(UISlider*)sender{
sender.value = (sender.maximumValue + sender.minimumValue) / 2;
}

Changing Default Behaviour of UISlider - No continuous sliding and Custom button

I want to achieve above type of UI using slider... But Slider should stop at only 3 positions
1. Extreme Right
2. Extreme Left
3. Center
Will it be possible to achieve this type of UI using UISlider in iPhone?? How should I achieve it??
EDIT:
I want to achieve same as TrackBar in VB.NET. Is it possible with the UISlider??? or please suggest me some other control/code in iPhone apart from SegmentedControl...
EDIT 2
int progressAsInt =(int)(slider.value + 0.5f);
NSString *newText =[[NSString alloc] initWithFormat:#"%d",progressAsInt];
sliderLabel.text = newText;
Look at the documentation for UISlider. The methods you are interested in are setMinimumTrackImage: forState: and setMaximumTrackImage: forState: to set the track, setThumbImage: forState: for the slider thumb
To make it stick at the beginning, middle or end, your viewcontroller should, in the valueChanged method linked to from the slider, determine the appropriate value and then use setValue: animated: to move the slider to the appropriate place. So, if your slider goes from 0 to 2, and the user changes it to 0.75, you assume this should be 1 and set the slider value to that.
Also - turn off the continuous property or the above won't work.

setting a default value for slider when app loads

In my iPhone app I'm using a slider for adjusting the volume and working fine.
But I'm not able to set a default value for slider when app loads.
I have seen that only when the slider is touched the value gets changed.But i need a default value when app loads.
My code is given below
- (IBAction)sliderChanged:(id)sender {
slider = (UISlider *) sender;
slider.minimumValue = 0.5;
slider.maximumValue = 2.2;
progressAsInt = slider.value ;
}
how can i solve this issue.
please help.Thanks in advance.
There are two ways to change default value of slider.
Using Interface builder. See attached picture and value of current property.
Using Code
You just need to write this one line in viewWillAppear delegate method.
-(void)viewWillAppear:(BOOL)animated{
slider.value = 1.0;
}
Hope this help.
First you'll need to set the slider to an IBOutlet iVar of the view controller where the slider is.
Then, in the viewDidLoad of that view controller, you can set the value you want.
(Also, you should be able to do it in Interface Builder, but I'm not very familiar with it).

How do I stop multiple UIButton pressing?

Imagine I have a UIView and to that I add 2 UIButtons.
I find that I can put a finger on one button, then, holding the first, I can touch the 2nd button with another finger. Both buttons will show their UIControlStateHighlighted images.
Is there a way to stop the 2nd touch working? I thought that multipleTouchEnabled = NO was the answer, but seems not!
Any ideas?
use a property of UIButton called exclusiveTouch
-(IBAction)button1Pressed {
button2.enabled = NO;
}
-(IBAction)button2Pressed {
button1.enabled = NO;
}
For touch down.
Then for touch up inside and touch up outside.
-(IBAction)button1Lifted {
button2.enabled = YES;
}
-(IBAction)button1Lifted {
button2.enabled = YES;
}
when you tab on 1st button, in Button's IBAction method,make a user interaction of a 2nd button disabled.(On 1st line)
and in last line of 1st button IBAction code, make 2nd button user interaction enabled.(on last line). set IBAction to touchDown.
& vice-versa.
add this property to each button\n
button.exclusiveTouch=YES;