How to add a UISegmentedControl to Section header of UITableView with margin?

Sebastian Boldt

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;
}

enter image description here

sha

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to add a UISegmentedControl to Section header of UITableView with margin?

From Dev

How can we add image in UITableView section header using swift?

From Dev

How to pad a UITableView section header?

From Dev

adding some margin below section header text of a UITableView

From Dev

How to make the first row of an UITableView a header of a section?

From Dev

How to Add a Left Margin to TableView Section Headers?

From Dev

How do I add a separator line for a custom UITableView header section nib?

From Dev

UITableView Section Header not showing

From Dev

How to add UITableView section using interface builder

From Dev

How to dynamically add rows to a specific UITableView section?

From Dev

How to add a Cell into a static section UITableView?

From Dev

How to add a Cell into a static section UITableView?

From Dev

UISegmentedControl behaves in a weird way on UITableView Header

From Dev

How to add bottom border to tableview section header

From Dev

how to add logout link in topmenu in header section?

From Dev

How to know what a tap has been made on a header section of a UITableView?

From Java

How to hide first section header in UITableView (grouped style)

From Dev

how to scroll uitableview, and section header in the top, visible and scroll to

From Dev

How to add left and right margin for the table cell section?

From Dev

How to add the UISegmentedControl in UINavigationBar?

From Dev

UITableView section header inset missing

From Dev

Adding UIButton to UITableView section header

From Dev

Set color of UITableView Section Header

From Dev

Section Header Not Showing in Programmatic UITableView

From Dev

How to programmatically add a search bar to a UITableView header?

From Dev

Asciidoctor how to add header and footer in title page and ignore margin

From Dev

How to add new section in group UITableView like adding new rows

From Dev

How to add data dynamically to UITableView when tapped on section headers

From Dev

How to manage section in UITableView

Related Related

  1. 1

    How to add a UISegmentedControl to Section header of UITableView with margin?

  2. 2

    How can we add image in UITableView section header using swift?

  3. 3

    How to pad a UITableView section header?

  4. 4

    adding some margin below section header text of a UITableView

  5. 5

    How to make the first row of an UITableView a header of a section?

  6. 6

    How to Add a Left Margin to TableView Section Headers?

  7. 7

    How do I add a separator line for a custom UITableView header section nib?

  8. 8

    UITableView Section Header not showing

  9. 9

    How to add UITableView section using interface builder

  10. 10

    How to dynamically add rows to a specific UITableView section?

  11. 11

    How to add a Cell into a static section UITableView?

  12. 12

    How to add a Cell into a static section UITableView?

  13. 13

    UISegmentedControl behaves in a weird way on UITableView Header

  14. 14

    How to add bottom border to tableview section header

  15. 15

    how to add logout link in topmenu in header section?

  16. 16

    How to know what a tap has been made on a header section of a UITableView?

  17. 17

    How to hide first section header in UITableView (grouped style)

  18. 18

    how to scroll uitableview, and section header in the top, visible and scroll to

  19. 19

    How to add left and right margin for the table cell section?

  20. 20

    How to add the UISegmentedControl in UINavigationBar?

  21. 21

    UITableView section header inset missing

  22. 22

    Adding UIButton to UITableView section header

  23. 23

    Set color of UITableView Section Header

  24. 24

    Section Header Not Showing in Programmatic UITableView

  25. 25

    How to programmatically add a search bar to a UITableView header?

  26. 26

    Asciidoctor how to add header and footer in title page and ignore margin

  27. 27

    How to add new section in group UITableView like adding new rows

  28. 28

    How to add data dynamically to UITableView when tapped on section headers

  29. 29

    How to manage section in UITableView

HotTag

Archive