我有一个包含 3 个段的 UISegmentedControl,我想在用户选择任何段时更改一个段 1 的宽度。这是代码:
// 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...
}
有什么线索吗?谢谢。
最佳答案
文档说“默认值为 {0.0},它告诉 UISegmentedControl 自动调整分段大小。”
关于iPhone - UISegmentedControl 段宽度 = 0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6538742/