关于如何更改UISlider
值有很多问题和答案,NsTimer
但我需要创建反向条件,我需要更改NSTimer
每个值更改的间隔UISlider
,并希望滑块值以相反的方式工作。那么任何人都可以帮助实现这一目标吗?
感谢您的方法和时间:)
您可以在方法中设置 Timer 再次设置间隔值,IBAction
例如UISlier
:-
.h 类:-
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
IBOutlet UILabel *lblTimer;
IBOutlet UISlider *timeSlider;
}
@property(nonatomic,strong)NSTimer *timer;
.m 类:-
- (void)viewDidLoad
{
[super viewDidLoad];
_timer=[[NSTimer alloc]init];
_timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateLable) userInfo:nil repeats:YES];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
int i=0;
-(IBAction)changeSlider:(UISlider*)sender
{
NSLog(@"%d",(int)sender.value);
[_timer invalidate];
_timer=[[NSTimer alloc]init];
_timer=nil;
_timer = [NSTimer scheduledTimerWithTimeInterval:(int)sender.value target:self selector:@selector(updateLable) userInfo:nil repeats:YES];
// i=0;
//text_field .text= [[NSString alloc] initWithFormat:@" Value %d ", (int)slider.value];
}
-(void)updateLable
{
[lblTimer setText:[NSString stringWithFormat:@"%d",i]];
i++;
}
代码输出