0

Trying to add a UISlider to UINavigationBar. I have it to where the slider shows, but when trying to change the value, it will not move. Here is the code in viewWillAppear. Note that this is on a child view and not the main parent view.

UIView *viewofslider = [[UIView alloc] initWithFrame:CGRectMake(160, 10, 40, 30)];
    UISlider *theslider = [[UISlider alloc] init];
    [theslider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
    [theslider setBackgroundColor:[UIColor clearColor]];
    theslider.minimumValue = 50.0;
    theslider.maximumValue = 150.0;
    theslider.continuous = YES;
    theslider.value = 100.0;
    [viewofslider addSubview:theslider];
    [self.navigationController.navigationBar addSubview:viewofslider];
4

2 回答 2

1

尝试将其添加到titleView视图控制器的导航项中viewWillAppear:

UISlider *theslider = [[UISlider alloc] init];
...
self.navigationItem.titleView = theslider;
于 2013-11-14T16:39:40.823 回答
1

要回答您的具体问题,我认为 40.0 的宽度viewofslider太窄,因此UISlider.

如果您将宽度更改viewofslider为 100.0,您应该能够与之交互。

但是,我同意 rmaddy 的评论,即您应该简单地将滑块添加到导航栏,没有明显需要UIView.

于 2013-11-14T16:40:58.517 回答