Questions tagged [uisegmentedcontrol]

UISegmentedControl is a class from UIKit in Apple iOS framework. A UISegmentedControl object is a horizontal control made of multiple segments, each segment functioning as a discrete button.

A UISegmentedControl object is a horizontal control made of multiple segments, each segment functioning as a discrete button. A segmented control affords a compact means to group together a number of controls.

A segmented control can display a title (an NSString object) or an image (UIImage object). The UISegmentedControl object automatically resizes segments to fit proportionally within their superview unless they have a specific width set. When you add and remove segments, you can request that the action be animated with sliding and fading effects.

You register the target-action methods for a segmented control using the UIControlEventValueChanged constant as shown below.

SWIFT

segmentedControl.addTarget(self, action: "action:", forControlEvents: .ValueChanged);

OBJECTIVE-C

[segmentedControl addTarget:self
                     action:@selector(action:)
           forControlEvents:UIControlEventValueChanged];

How you configure a segmented control can affect its display behavior:

If you set a segmented control to have a momentary style, a segment doesn’t show itself as selected (blue background) when the user touches it. The disclosure button is always momentary and doesn’t affect the actual selection.

In versions of iOS prior to 3.0, if a segmented control has only two segments, then it behaves like a switch—tapping the currently-selected segment causes the other segment to be selected. On iOS 3.0 and later, tapping the currently-selected segment does not cause the other segment to be selected.

Customizing Appearance In iOS v5.0 and later, you can customize the appearance of segmented controls using the methods listed in Customizing Appearance. You can customize the appearance of all segmented controls using the appearance proxy (for example, [UISegmentedControl appearance]), or just of a single control.

When customizing appearance, in general, you should specify a value for the normal state of a property to be used by other states which don’t have a custom value set. Similarly, when a property is dependent on the bar metrics (on the iPhone in landscape orientation, bars have a different height from standard), you should make sure you specify a value for UIBarMetricsDefault.

In the case of the segmented control, appearance properties for UIBarMetricsLandscapePhone are only respected for segmented controls in the smaller navigation and toolbars that are used in landscape orientation on the iPhone.

To provide complete customization, you need to provide divider images for different state combinations, using setDividerImage:forLeftSegmentState:rightSegmentState:barMetrics::

SWIFT

// Image between two unselected segments.
mySegmentedControl.setDividerImage(myImage, forLeftSegmentState: UIControlState.Normal,
    rightSegmentState: UIControlState.Normal, barMetrics: UIBarMetrics.Default)

// Image between segment selected on the left and unselected on the right.
mySegmentedControl.setDividerImage(myImage, forLeftSegmentState: UIControlState.Selected,
    rightSegmentState: UIControlState.Normal, barMetrics: UIBarMetrics.Default)

// Image between segment selected on the right and unselected on the left.
mySegmentedControl.setDividerImage(myImage, forLeftSegmentState: UIControlState.Normal,
    rightSegmentState: UIControlState.Selected, barMetrics: UIBarMetrics.Default)

OBJECTIVE-C

// Image between two unselected segments.
[mySegmentedControl setDividerImage:image1 forLeftSegmentState:UIControlStateNormal
                  rightSegmentState:UIControlStateNormal barMetrics:barMetrics];
// Image between segment selected on the left and unselected on the right.
[mySegmentedControl setDividerImage:image1 forLeftSegmentState:UIControlStateSelected
                  rightSegmentState:UIControlStateNormal barMetrics:barMetrics];
// Image between segment selected on the right and unselected on the right.
[mySegmentedControl setDividerImage:image1 forLeftSegmentState:UIControlStateNormal
                  rightSegmentState:UIControlStateSelected barMetrics:barMetrics];

For more information about appearance and behavior configuration, see Segmented Controls.

1825 questions
0
votes
1 answer

Simulating UISegmentedControl with 2 UIButtons

I want to have two custom buttons to simulate how a UISegmentedControl behaves (switch button text color and image) Here is what I have so far: - (IBAction)byDateTapped:(UIButton *)sender { UIColor *darkColor = [UIColor colorWithRed:52/255…
Kaitis
  • 628
  • 9
  • 21
0
votes
4 answers

Changing the tint color for only the selected segment in swift

I am re-doing one of my projects in swift from objective-c and i have one function i use in objective-C that i can't get translated properly. This is the Objective-C code - (void)segmentAction:(UISegmentedControl *)sender { NSLog(@"Segment"); …
inVINCEable
  • 2,167
  • 3
  • 25
  • 49
0
votes
2 answers

How can i get each Segment on uisegmentcontroler with diffrent image?

I need different images on each segment of UISegmentController, I tried many solutions in Stackoverflow but none of them satisfied my need. Im new to IOS, So please help me. Also change image on each selection with some other jpg files. Presently…
0
votes
3 answers

UISegmentedControl setFrame not working

I am trying to add segmented control to tableviewheader. I am using the following code to do that UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"ALL", @"HOUSE", @"SENATE",…
Deepak ML
  • 79
  • 1
  • 13
0
votes
1 answer

How to update UITableView datasource when user changed the value in UITableViewCell

First and foremost, this is an app for teacher to make attendance, the attendance will update back to my server. My TableViewCell is customised as below. @interface TvcStudentClassSession : UITableViewCell @property (strong, nonatomic) IBOutlet…
TPG
  • 2,811
  • 1
  • 31
  • 52
0
votes
1 answer

Custom segmented control

I need to create a segmented control which is looking like this. Any idea ? Thanks
Niko
  • 2,543
  • 1
  • 24
  • 29
0
votes
1 answer

unable to get selected segmentedcontrol to highlight on button click

The following method changes the segmented control view from button click but I can't seem to make the selected segmented control item highlighted. I just need show the segmented control index 1 is selected. -…
Dameon Bryant
  • 39
  • 1
  • 6
0
votes
2 answers

Untouchable UITableViewCell

I have table view cell with segmented control on it. I want to make my cell untouchable. It shouldn't highlight grey when user touches it. If I set user interaction enabled property to false, segmented control, doesn't work. How should I make my…
0
votes
2 answers

UIButton to perform UISegment Control action

I have a UISegmented control in my app. I also have a custom button. I would like this custom button to return the Segment back to index 0 but also perform index 0s method. Here is my segmented control; - (IBAction)segmentSwitch:(id)sender { …
DevC
  • 6,982
  • 9
  • 45
  • 80
0
votes
2 answers

Enabling UITextField when changing SegmentedControl

I have a UIViewController that have 2 segmented controls which are Takeaway and Delivery, and 5 UITextFields which are adressField, stateField, cityField, postcodeField and phoneField. I would like to disable user input for each UITextfield except…
Faiz Mokhtar
  • 938
  • 1
  • 10
  • 24
0
votes
2 answers

Multiple user interafce in xcode 6 [swift] with UISegmentedcontrol

I'm starting to develop apps in Xcode 6 with swift. It's my first experience with programming. I'm developing an app that needs to have more than one user interface, and I want to switch between them with a segmented control. Can anybody tell me…
0
votes
4 answers

How to change only text color when UISegmentedControl value changed?

I am using UISegmentedControl in my app and i could able to toggle the text color when it changes the state. But by default selected segment contains a different tint color like below image I do not want to have different tint color when it is in…
thavasidurai
  • 1,972
  • 1
  • 26
  • 51
0
votes
1 answer

UISegmentedControl, 7+, set widths -- no longer centres

This is 7+ only, Make a UISegmentedControl with say four segments, in Storyboard sit in in the middle of the iPhone (it'll be about 200 wide), run the app, and of course it is centered. I'm simply forcing the widths of each item like this... (all…
Fattie
  • 27,874
  • 70
  • 431
  • 719
0
votes
1 answer

How to make a single UISegmentedControl section detect multiple touches

I am using a UISegmentedControl section to show an action sheet when pressed. The action sheet has 2 date pickers one to set a from date and one to set a to date. When the action sheet is finished with it hides away and does what it needs to do,…
TinMan7757
  • 148
  • 2
  • 10
0
votes
3 answers

Using Storyboard Segues with Segmented Control

I have a Segmented Control that I'm using to switch between three view controllers. My first tableview is embedded in a navigation controller where the segmented control is in the navigation controller. I also have two custom segues in the…
Jared
  • 3,651
  • 11
  • 39
  • 64
1 2 3
99
100