Reputation: 1987
I'm trying to increase the length of a UISlider at runtime, but it doesn't work. Here's what I am doing.
- (IBAction)lengthenADSR:(UIButton *)sender {
CGRect aFrame = CGRectMake(870, 351, 200, 28);
mainAttackSlider = [mainAttackSlider initWithFrame:aFrame];
[mainAttackSlider removeFromSuperview];
[self.view addSubview:mainAttackSlider];
[mainAttackSlider setNeedsDisplay];
}
What am I doing wrong? Or is it not possible to change the UISlider length at run time? Thanks.
Upvotes: 0
Views: 249
Reputation: 21902
I'm extrapolating your code into what I think you did already so I apologize if I make wrong assumptions. It sounds like your view already has a slider, you're then making a new one with a fixed length, so I'm not sure what to set the new length to. But let's pretend your method increases the length by 10 every time you call it. It'd look something like this:
- (IBAction)lengthenADSR:(UIButton *)sender {
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
mainAttackSlider.frame = CGRectMake(mainAttackSlider.frame.origin.x, mainAttackSlider.frame.origin.y, mainAttackSlider.frame.size.width+10, mainAttackSlider.frame.size.height);
}];
}
Adjust as you see fit. Next time, you should consider making sure your question is unambiguous so you can get more accurate help.
Upvotes: 1