我想知道如何在运行时创建UISlider。
答案 0 :(得分:5)
您可以像其他视图一样添加滑块:
UISlider *slider = [[[UISlider alloc] initWithFrame:CGRectMake(50, 50, 100, 40)] autorelease];
[slider addTarget:self action:@selector(controlValueChanged:) forControlEvents:UIControlEventValueChanged];
slider.minimumValue = 100.00;
slider.maximumValue = 1000.00;
slider.continuous = YES;
[self.view addSubview:slider];
使用适合您需要的框架,并添加到相应的视图(我在此示例中使用了self.view)。您可以根据需要随意配置。 ; - )
答案 1 :(得分:1)
CGRect frame = CGRectMake(50, 170, 205, kSliderHeight);
customSlider = [[UISlider alloc] initWithFrame:frame];
[customSlider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
customSlider.backgroundColor = [UIColor clearColor];
UIImage *stetchLeftTrack = [[UIImage imageNamed:@"yellowslide.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
UIImage *stetchRightTrack = [[UIImage imageNamed:@"orangeslide.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
[customSlider setThumbImage: [UIImage imageNamed:@"slider_ball.png"] forState:UIControlStateNormal];
[customSlider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
[customSlider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];