Reputation: 1397
I have a uisegmentedcontrol within a horizontally scrolling uiscrollview. The scrollview is working just fine and the content is resized according to the width of the segmentedcontrol. The segmented control detects the touches on those segments that are visible when first displayed. If I scroll to the right I am unable to select the newly displayed segments. The cuttof is not exactly a segment either, its what was initially displayed, like if there was a view clipping it. thanks for the help, i have deselected clip subviews from the scrollview.
// creates segmented control to indicate test to show on graph
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:self.labels];
segmentedControl.frame = CGRectMake(15, 41, 285, 30);
segmentedControl.autoresizingMask =
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.selectedSegmentIndex = 0;
segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[segmentedControl addTarget:self action:@selector(testChange:) forControlEvents:UIControlEventValueChanged];
//checks the length of the text in each segment and asjusts control accordingly
int x = 0;
segmentWidth = 0.0;
for (id segment in [segmentedControl subviews])
{
for (id label in [segment subviews])
{
if ([label isKindOfClass:[UILabel class]])
{
[label setTextAlignment:UITextAlignmentCenter];
[label setFont:[UIFont boldSystemFontOfSize:12]];
CGFloat textWidth = [[segmentedControl titleForSegmentAtIndex:x] sizeWithFont:[UIFont boldSystemFontOfSize:12.0]].width + 20;
[segmentedControl setWidth:textWidth forSegmentAtIndex:x];
segmentWidth += textWidth;
}
}
x++;
}
self.testSegment = segmentedControl;
[segmentedControl release];
//adds segmentedcontroll to scrollview, and adjusts contensize
[scrollView setContentSize:CGSizeMake(segmentWidth + 45, scrollView.frame.size.height)];
[scrollView showsHorizontalScrollIndicator];
[scrollView addSubview:testSegment];
Upvotes: 0
Views: 1054
Reputation: 1397
fixed, problem is that I had set the frame of the segmented control before calculating the widths of each segment.
segmentedControl.frame = CGRectMake(15, 41, segmentWidth+20, 30);
before
self.testSegment = segmentedControl;
Upvotes: 1