问题描述
可以设置max& iPhone中 UISlider
控件的最小值。因此滑块可以工作 - 好 - 好。
It is ok to set the max & min value for a UISlider
control in iPhone. Accordingly slider will work - OK - Good.
首先,我将举例说明我想要实施的内容。
First, I will give an example of what exactly I want to implement.
- 在iPad中默认使用日历应用程序。
- 打开日历,在底部 - 您可以看到日/周/月列表
- 当您滑动手指时,滑动时会看到一个弹出菜单。
- 我想在滑块上实现相同的功能。
- In iPad comes with Calendar application as a default.
- Open calendar, at the bottom - you can see day/week/month listing
- When you slide your finger on it, you will see a pop up menu when sliding.
- I want to implement the same functionality on slider.
我正在努力,但如果我能够得到x坐标,我可以很容易地实现它。任何其他实现相同的建议都是最受欢迎的。
I am trying hard, But if I am able to get x co-ordinate, I can easily implement it. Any other suggestion for implementing same are most most welcome.
推荐答案
从UILabel开始测试(只需在其中写一些内容)并向其添加IBOulets,以及UISlider。接下来,为滑块添加更改值的IBAction。
Start out with a UILabel for testing (just write something in it) and add IBOulets to it, as well as the UISlider. Next, add a IBAction for "value changed" for the slider.
然后,您需要计算两个值以确定应放置标签的位置 - 从左侧调整,以及滑块的每个值的像素。你的 @interface
可能如下所示:
You then need to calculate two values to figure out where your label should be placed -- adjustment from left, and pixels per value for the slider. Your @interface
might look like this:
@interface sliderViewController : UIViewController {
IBOutlet UISlider *slider;
IBOutlet UILabel *label;
float pixelsPerValue;
float leftAdjust;
}
-(IBAction) sliderValueChanged:(id)sender;
@end
例如viewDidLoad:对于你的视图控制器,你可以计算两个浮点数。
In e.g. viewDidLoad: for your view controller, you do the calculation for the two floats.
- (void)viewDidLoad {
float width = slider.frame.size.width;
pixelsPerValue = width / (slider.maximumValue - slider.minimumValue);
leftAdjust = slider.frame.origin.x;
[super viewDidLoad];
}
最后,您的IBAction可能如下所示:
And finally, your IBAction might look like this:
-(IBAction) sliderValueChanged:(id)sender
{
NSLog(@"changed");
CGRect frame = label.frame;
frame.origin.x = leftAdjust + (pixelsPerValue * slider.value);
label.frame = frame;
}
希望有所帮助。
这篇关于菜单滑块 - iPhone在滑动时获得UISlider指针的x坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!