How would I define the frame for a UISegmentedControl
? I would like the segmented control to appear at the bottom of a container view
i.e UIView
.
Enter Swift as Language and choose Next. Go to the Storyboard and drag a Segmented Control to the top of the main view. Also drag a Label to the view and place it below the Segmented Control. Select the label and give it a text of First Segment selected.
this one is perfect I tested.....
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 435)]; scroll.contentSize = CGSizeMake(320, 700); scroll.showsHorizontalScrollIndicator = YES; NSArray *itemArray = [NSArray arrayWithObjects: @"One", @"Two", @"Three", nil]; UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray]; segmentedControl.frame = CGRectMake(35, 200, 250, 50); segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain; [segmentedControl addTarget:self action:@selector(MySegmentControlAction:) forControlEvents: UIControlEventValueChanged]; segmentedControl.selectedSegmentIndex = 1; [scroll addSubview:segmentedControl]; [segmentedControl release]; [self.view addSubview:scroll];
Then add your method in your class.
- (void)MySegmentControlAction:(UISegmentedControl *)segment { if(segment.selectedSegmentIndex == 0) { // code for the first button } }
For deprecated UISegmentedControlStyle you can take a look on this URL.
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