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

发布于 2025-01-04 22:41:35 字数 732 浏览 0 评论 0原文

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

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,滑块不会出现。任何帮助将不胜感激!

I'm trying to programmatically add a vertical UISlider to a UIView, with a variable height. This is what I have so far

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];

My problem is that whenever fullSize is > 320, the slider wont appear. Any help would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

乖乖兔^ω^ 2025-01-11 22:41:35

你可以试试这个
然后制作滑块值方法

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

You can try this
and make slider value method also

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];

then -(void)slider:Action

梦情居士 2025-01-11 22:41:35

UIScrollView 的框架不应大于包含 UIView 的矩形。您应该更改 UIScrollView 的 contentSize,而是设置其高度/宽度。

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

The UIScrollView's frame should not be bigger than the containing UIView's rect. You should be altering the UIScrollView's contentSize, setting its height/width instead.

UIScrollView * scrollview ... ;
scrollview.contentSize = CGSizeMake(newwidth,newheight);
枉心 2025-01-11 22:41:35

试试这个代码:

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
}

Try this Code:

1.Create a new slider

-(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.For Slider Actions

-(void)sliderAction:(id)sender
{
    float value = [sender floatValue];
    NSLog(@"%@",value);
    //-- Do further actions
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文