当我尝试以编程方式将UISlider添加到UIView时,如果宽度太高,则不会出现

时间:2012-02-13 17:16:50

标签: iphone objective-c ios uiview uislider

我正在尝试以编程方式将垂直UISlider添加到具有可变高度的UIView。这就是我到目前为止所拥有的

int fullSize = [myBottle.barBottem intValue] - [myBottle.barTop intValue];
    CGRect frame = CGRectMake(200, 150,fullSize, 23);
    slider = [[UISlider alloc] initWithFrame:frame];
    [slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
    [slider setBackgroundColor:[UIColor clearColor]];
    slider.minimumValue = 0.0;
    slider.maximumValue = fullSize;
    slider.continuous = YES;
    slider.transform = CGAffineTransformMakeRotation(M_PI * -
                                                0.5);;
[self.view addSubview:slider];

我的问题是每当fullSize为> 320,滑块不会出现。任何帮助将不胜感激!

3 个答案:

答案 0 :(得分:1)

你可以试试这个 并使滑块值方法也

UISlider *loslider=[[UISlider alloc]initWithFrame:CGRectMake(60, 80, 200, 30)];

    [loslider addTarget:self action:@selector(slider_Action:)  forControlEvents:UIControlEventValueChanged];

    [loslider setMaximumValue:100.0];
    [loslider setMinimumValue:0.0];
    [loslider setValue:0.0];
    [self.view addSubview:loslider];

然后 - (void)slider:Action

答案 1 :(得分:0)

UIScrollView的框架不应大于包含UIView的rect。你应该改变UIScrollView的contentSize,改为设置它的高度/宽度。

UIScrollView * scrollview ... ;
scrollview.contentSize = CGSizeMake(newwidth,newheight);

答案 2 :(得分:0)

试用此代码:

1.创建一个新滑块

-(IBAction)mySlider
{ 
    CGRect frame = CGRectMake(20, 25, 200.0, 10.0);
    UISlider *slider = [[UISlider alloc] initWithFrame:frame];
    [slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
    [slider setBackgroundColor:[UIColor clearColor]];
    slider.minimumValue = 0.0;
    slider.maximumValue = 50.0;
    slider.continuous = YES;
    slider.value = 25.0;
    [self.view addSubview:slider];
}

2.对于滑块动作

-(void)sliderAction:(id)sender
{
    float value = [sender floatValue];
    NSLog(@"%@",value);
    //-- Do further actions
}