问题描述
我是iOS编程的初学者,我正在寻找问题的答案.
I'm a beginner in iOS programming and I'm looking for an answer to my question.
我在UITableViewCell中有一个UISlider,我试图得到这种配置:Label-Slider-DetailLabel(dynamic).
I have a UISlider inside a UITableViewCell and I'm trying to get this disposition: Label-Slider-DetailLabel(dynamic).
这是我的代码:
cell = [tableView dequeueReusableCellWithIdentifier:@"SelectedMeetingCell"];
[cell.textLabel setText:@"Duration"];
[cell.detailTextLabel setText:[Utilities StringFromDuration:Agenda.InitialDuration.doubleValue]];
sliderCell = (SliderCell*)[[UIViewController alloc] initWithNibName:@"SliderCell" bundle:nil].view;
[sliderCell setDelegate:self];
[sliderCell.slider setValue:Agenda.InitialDuration.doubleValue];
[cell.contentView addSubview:sliderCell];
sliderCell.slider.frame = CGRectMake(100, 0, 500, 44);
最后一行是我以前习惯放置滑块的方式.它适用于iPad,但不适用于iPhone版本.有什么方法可以根据设备自动调整滑块的宽度吗?
The last line is the way I used to place my slider the way I wanted to be. It works great for iPad but not at all for the iPhone version. Is there any way to resize the width of my slider automatically depending on the device ?
(SliderCell是具有UISlider @property的UITableViewCell)
(SliderCell is a UITableViewCell with a UISlider @property)
谢谢大家!
推荐答案
代替对值进行硬编码,您可以获取容器视图的宽度并将滑块宽度设置为百分比.
Instead of hard coding the values, you could get the container views width and set the sliders width as a percentage of it.
CGRect superViewFrame = slider.superView.frame;
CGRect sliderFrame = slider.frame;
sliderFrame.size.width = <your choice for eg, superViewFrame.size.width * 0.3f>
sliderFrame.origin.x = <your choice for eg, superViewFrame.size.width * .2f>
slider.frame = sliderFrame;
这篇关于UISlider更改宽度取决于设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!