段控件无法重新定位垂直位置。它在图像中显示。任何人都可以帮我定位段控件。
int offset = BAR_OFFSET + 40 * bars.count;
for (int i = bars.count; i < guessRows; i++)
{
UISegmentedControl *bar = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:@"", @"", @"", nil]];
bar.segmentedControlStyle = UISegmentedControlStyleBar;
bar.transform = CGAffineTransformMakeRotation(M_PI_2);
bar.momentary = YES;
[bar addTarget:self action:@selector(submitGuess:)
forControlEvents:UIControlEventValueChanged];
CGRect frame = bar.frame;
frame.origin.y = offset; // position it below the last bar
frame.origin.x = 20; // give it some padding on the left
[self.view addSubview:bar]; // add the bar to the main view
[bars addObject:bar];
[bar release];
}
答案 0 :(得分:2)
您可以通过编程方式创建分段控件并设置框架以维护分段控件位置并将分段控件添加到视图控制器中,如下所示: -
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
segmentedControl.frame = CGRectMake(35, 200, 250, 50);
segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
segmentedControl.selectedSegmentIndex = 1;
[self.view addSubview:segmentedControl];
答案 1 :(得分:1)
问题来自您的offset
var。在线:
frame.origin.y = offset; // position it below the last bar
更改其值(增加它以降低视图的位置)并尝试找到正确显示控件的值。