1

私はiOSプログラミングの初心者であり、私の質問に対する答えを探しています。

UITableViewCell内にUISliderがあり、次の配置を取得しようとしています: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バージョンにはまったく機能しません。デバイスに応じてスライダーの幅を自動的に変更する方法はありますか?

(SliderCellは、UISlider @propertyを持つUITableViewCellです)

よろしくお願いします!

4

2 に答える 2

2

値をハードコーディングする代わりに、コンテナビューの幅を取得し、スライダーの幅をそのパーセンテージとして設定できます。

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;
于 2012-10-14T18:34:26.220 に答える
0

を呼び出すことでデバイスのサイズを取得できますself.view

sliderCell.slider.frame = CGRectMake(100, 0, self.view.frame.size.width, self.view.frame.size. height);

ビューのサイズに応じて減算または除算したい場合があります

于 2012-10-14T19:06:03.250 に答える