【问题标题】:UISegmentedControl with image returns null for titleForSegmentAtIndex带有图像的 UISegmentedControl 为 titleForSegmentAtIndex 返回 null
【发布时间】:2015-07-13 22:07:59
【问题描述】:

我有一个分段控件,其中有 4 个分段。其中三个有标签,一个有图像。 当我使用 titleForSegmentAtIndex 时,它返回前三个的精细文本,但对于图像段,它返回 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];

【问题讨论】:

  • 我认为您需要为第 4 段设置标题和图像。并设置标题颜色清晰,因此您只能看到与预期结果相同的图像。并且您还将获得第 4 段的标题。

标签: ios ipad uisegmentedcontrol


【解决方案1】:

titleForSegmentAtIndex 如果您没有设置标题,则不会返回标题。您将需要改用 imageForSegmentAtIndex。

你有我们可以看到的代码 sn-p 吗?

【讨论】:

  • 啊,使用 imageForSegmentAtIndex 为我工作 :) 谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-11-19
  • 2012-11-07
  • 1970-01-01
  • 1970-01-01
  • 2013-03-01
  • 1970-01-01
相关资源
最近更新 更多