我有一个问题,你可以UISliders
在IOS
什么范围内定制它们?
我想在iPhone中实现一个类似“解锁滑块”的滑块。
但似乎 IOS 没有提供任何“标准”方式来实现这样的滑块?
是否可以实现标准 UISlider 并将其设置为 min.value (0.0) 和 maximum.value (0.5)。如果滑块“击中”一个大于 (0.01) 的值,它应该自动拉回最小值 (0.0)。
如果它达到最大值(0.5),启动一个事件,然后自动拉回 min.value?
感谢所有帮助!
尝试这个。我在我的项目中使用它
滑块.h
@class Slider;
@protocol SliderDelegate <NSObject>
@required
- (void) slideEnd;
@end
@interface Slider : UISlider
@property (nonatomic, weak) id<SliderDelegate> delegate;
滑块.m
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setMinimumTrackImage:YOUR_MINIMUM_TRACK_IMG forState:UIControlStateNormal];
[self setMaximumTrackImage:YOUR_MAXIMUM_TRACK_IMG forState:UIControlStateNormal];
[self setThumbImage:YOUR_THUMB_IMAGE];
self.minimumValue = 0.0;
self.maximumValue = 1.0;
self.value = 0.0;
[self addTarget:self action:@selector(moved:) forControlEvents:UIControlEventTouchUpInside];
[self addTarget:self action:@selector(moved:) forControlEvents:UIControlEventTouchUpOutside];
}
return self;
}
- (void) moved:(UISlider *) sender
{
if (self.value != 1.0) {
[self setValue: 0 animated: YES];
} else {
[[self delegate] slideEnd];
[self setValue: 0 animated: YES];
}
}
像这样实现它:
[self setSlider:[[Slider alloc] initWithFrame:CGRectMake(645, 25, 120, 50)]];
[[self view] addSubview:[self slider]];
[[self view] bringSubviewToFront:[self slider]];
[[self slider] setDelegate:self];
不要忘记实现委托方法:
- (void)slideEnd {
// Things you want to do when slide ends
}