UISegmentedControl with image returns null for titleForSegmentAtIndex

UISegmentedControl with image returns null for titleForSegmentAtIndex

我有一个分段控件,其中有 4 个分段。其中三个有标签,一个有图像。 当我使用 titleForSegmentAtIndex 时,前三个 returns 精细文本,但对于图像片段,它返回 null。 有什么想法吗?


NSArray *segmentArray = [[NSArray alloc] initWithObjects: @"One", @"Two", @"Three",[UIImage imageNamed:IMAGE_ANY_NUMBER], nil];
self.timeSegments = [[UISegmentedControl alloc] initWithItems:segmentArray];
    self.timeSegments.tintColor = [UIColor colorWithRed: 0x77/255.0 green:0x77/255.0 blue:0x77/255.0 alpha:1.0];
    self.timeSegments.backgroundColor = [UIColor colorWithRed: 0xFB/255.0 green:0xFB/255.0 blue:0xFB/255.0 alpha:1.0];
    [self addSubview:self.segmentArray];

titleForSegmentAtIndex 不会 return 如果您还没有设置标题。您将需要改用 imageForSegmentAtIndex。

你有我们可以看到的代码片段吗?