How to auto-stretch UISegmented Control horizontally to fill full UITableViewCell? In a manner in which it will auto-resize after an orientation change too.
I have tried the following however this still doesn't work. The segmented control appears in the cell on the left, but does not stretch itself across horizontally.
NSArray *itemArray = [NSArray arrayWithObjects: @"Feet", @"Metric", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
segmentedControl.selectedSegmentIndex = [self.config.isMetric boolValue] ? 1 : 0;
segmentedControl.contentMode = UIViewContentModeScaleToFill;
[cell.contentView addSubview:segmentedControl];
cell.contentView.contentMode = UIViewContentModeScaleToFill;
[segmentedControl release];
You would need to set the frame for the UISegmentedControl which in your case would be the same as the cell's frame.
segmentedControl.frame = cell.frame;
segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With