Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - UISegmentedControl segment width = 0?

Tags:

iphone

I have a UISegmentedControl with 3 segments and I want to change the width of one segment 1 when the user chooses any segment. Here is the code:

// the UISegmentedControl is created
[segmentedControl addTarget:self action:@selector(changeIt:) 
               forControlEvents:UIControlEventValueChanged];

//... 

// and this is the changeIt method:


- (void) changeIt:(id)sender {

    // discover the original width of segment 1, to restore it later
    UISegmentedControl *seg = (UISegmentedControl*)sender;
    CGFloat segWidth = [seg widthForSegmentAtIndex:1];
    // At this point segWidth = 0 ?????????????????
    // note: seg is not nil at this point. Printing seg to console shows it is
    // a valid UISegmentedControl...

}

Any clues? Thanks.

like image 717
Duck Avatar asked Jun 30 '11 17:06

Duck


People also ask

How do I customize the appearance of segmented controls in iOS?

In iOS 5 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.

How does the disclosure button work in iOS segmented controls?

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.

What is segmented control in Uis?

A horizontal control that consists of multiple segments, each segment functioning as a discrete button. 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.

How do I animate segments in the uisegmentedcontrol?

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.


1 Answers

Documentation says "The default value is {0.0}, which tells UISegmentedControl to automatically size the segment."

like image 73
Tatvamasi Avatar answered Sep 27 '22 17:09

Tatvamasi