开发者

iPhone - UISegmentedControl segment width = 0?

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 ?????????????????
    开发者_StackOverflow社区// note: seg is not nil at this point. Printing seg to console shows it is
    // a valid UISegmentedControl...

}

Any clues? Thanks.


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


You probably want to use the UISegmentedController methods – removeSegmentAtIndex:animated: and either – insertSegmentWithTitle:atIndex:animated: or – insertSegmentWithImage:atIndex:animated:, depending on whether you want a title or an image for the segment.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜