iPhone - UISegmentedControl 段宽度 = 0?

标签 iphone

我有一个包含 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/

相关文章:

iphone - 如何在一个单元格(tableView)中显示两个对象?

iphone - 我可以创建没有颜色信息的顶点缓冲区对象吗?

iphone - 从用户的 iTunes 库中导出视频

iphone - 日期更改后的 UIDatePicker

iphone - 不透明 UIImageView 内图像的透明度

iphone - 如何为表格中的每个部分添加标题标题

iphone - 向项目添加新的源文件会更改主应用程序中的调用堆栈

ios - iPhone:URL 方案不适用于邮件客户端

iphone - 除了 UIWebView 之外,Cocoa 中还有 HTML 包装器吗?

iphone - 编辑时如何将图像叠加添加到UIImagePickerControllerSourceTypePhotoLibrary?