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

In a UISegmentedControl, how do I set the normal color separate from the selected color?

This is the effect that I'm going for: This is what I have so far: Cocoa does not allow you to set both an icon and text for each segment, so I was forced to burn the text into an image: self.segmentedControl = [[UISegmentedControl alloc]…
Pwner
  • 3,714
  • 6
  • 41
  • 67
0
votes
1 answer

Distinction between one UITableView displaying different array in segmented control. How to implement swipe for delete only in one segment

I have one UITableView, two arrays and segmented control. When segmented control index is "1", UITableView display data from first array, when index is "2" - second array. I want to swipe to delete function only in second segment. How can I do that?…
migari
  • 131
  • 2
  • 10
0
votes
1 answer

iphone segmented control and uitableview

I have a UITableView with a segmented control at the top. When you tap on the different segments, I want the table to reload with a new different sized array. I have tried everything including [self.tableView reloadData]. When you click on a…
Emma
  • 1
  • 1
0
votes
1 answer

Confusion about unrecognized selector sent to instance

Sooooo, I keep getting this error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CardGameViewController matchModeSegmentedControl:]: unrecognized selector sent to instance 0x8c84da0' I've been doing a bunch of…
0
votes
3 answers

Multiple segmented controls

i need to implement two segmented controls. The result will be different considering the index of the two segmented controls. Considering that in the first one each index has an int fixed number (not variable) and the second controls has an equation…
MrKinisia
  • 35
  • 5
0
votes
1 answer

Can I redraw a UISegmentedControl programatically? How?

Say I have a UITextField (default blank), a UISegmentedControl (default 2 segments named "1" & "2"), and a UILabel (default text "None") in my nib. I want to be able to do the following: I want to enter a number in the UITextField, say "3" I then…
Chris F
  • 14,337
  • 30
  • 94
  • 192
0
votes
2 answers

Why if i change the segmentedControl index the label won't change?

Hi i am trying to change label text when changing segmented control. Here's the code: #import "FirstViewController.h" @interface FirstViewController () @end @implementation FirstViewController @synthesize segmentedControl; @synthesize…
MrKinisia
  • 35
  • 5
0
votes
0 answers

Creating a prefixed UISlider SWIFT

I've been trying to achieve such a result as below for sometime now i've been looking on cocaControls, but all controls is not working in swift, so my question is what is the easiest way and how can i create such a control as below where it snaps to…
Peter Pik
  • 11,023
  • 19
  • 84
  • 142
0
votes
1 answer

UISwitch and UISegmentedControl disappear in cell on iOS 8.1.1

I get a strange issue when using my app on iOS 8.1.1 and 8.1.2 (iPhone 6). Some components (UISwitch and UISemgentedControl) in my menu cells have disappeared. I can't reproduce it on simulator, since I did not find iOS 8.1.1 sim on xcode 6.1 or…
KIDdAe
  • 2,714
  • 2
  • 22
  • 29
0
votes
2 answers

Swift - Use segmented control to navigate to different view controllers

I've got an app with a mapViewController embedded in a navController. In the mapVC ive got a single bar button item which when clicked I want to conditionally "push" segue to one of a number of different view controllers. To achieve that ive set up…
lozflan
  • 835
  • 10
  • 23
0
votes
0 answers

Custom UISearchBar hides when is active iOS

i am developing an app ios7, got a custom UISearchBar at top of a UITableView with an UISegmetedControl, the problem is when i start to search, searchBar goes left and hide, so is imposible to handle it, how can i make the UISearchBar stay on it's…
Randy
  • 33
  • 7
0
votes
1 answer

How to add more than 6 segments with image on iphone using uisegmentcontrol

The thing is i can add segments as much as i want if i use text but if i use image means i can not able to add more than 6 segments on iphone. help me out. UIImage* resetImage = [UIImage imageNamed:@"Reset_V1"]; UIImage* wlwwImage = [UIImage…
user3714144
  • 159
  • 3
  • 13
0
votes
0 answers

UISegmentedControl set selected image

I want my UISegmentedController to keep the same background color when selected, but just change the color of the image when selected. Here's a picture of what I'm trying to…
jclay
  • 988
  • 1
  • 7
  • 10
0
votes
1 answer

Using Segmented Controller to Change Views

I am aware that this question has been asked previously, and I know how to actually change views or view controllers w/ a segmented control, but I have a more specific problem. I had my UI designed, and the designer used something that appeared to…
0
votes
0 answers

UISearchController UISegmentedControl deselect all items

Is there a way to deselect all item of UISegmentedControl in UISearchController? I need to deselect some segment if i tap on a already selected segment. So i will enable all options for search. Only what i can do now for that - create segment "All",…
Oleg Sobolev
  • 3,286
  • 2
  • 16
  • 29
1 2 3
99
100