I recently added a segmented control to a section header of my tableview, everything works fine, but it resizes the wrong way .. i want to apply some margin, but if i set the frame it does not have any effect on the size of the segmented control ? What i am doing wrong ? here is my code :
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if(section == 0) {
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"Segment 1", @"Segment 2",@"Segment 3"]];
segmentedControl.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.95];
[segmentedControl setFrame:CGRectMake(10, 0, self.view.bounds.size.width-10, self.view.bounds.size.height)];
return segmentedControl;
}
return nil;
}
You're returning UISegmentedControl instance and for obvious reasons you can't configure much inside the control. Instead of that try to create a UIView as a header view and add segmented control inside as a subview. This way you will be able to configure position of segmented control inside this container view just fine.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments