我正在为每个段创建一个带有自定义图像的 UISegmentedControl。以编程方式,这对我有用:
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithFrame:CGRectMake(30, 0, 170, 31)];
segmentedControl.tintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ebd-toolbar-bg"]];
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"eatIcon"] atIndex:0 animated:NO];
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"buyIcon"] atIndex:1 animated:NO];
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"doIcon"] atIndex:2 animated:NO];
segmentedControl.contentMode = UIViewContentModeScaleToFill;
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
但是,该段的自定义图像并没有完全填满该段,并且背景显示了一点。问题是背景图像没有相同的颜色,所以看起来很奇怪,如下所示。您可以在每个段周围看到一点黑色。
我尝试使用UIViewContentModeScaleToFill
,但这也不起作用。有没有办法设置段的图像大小?如果是这样,怎么做?它必须有多大?