5

我正在使用背景和分隔线图像来自定义UISegmentedControl. 但是,分隔图像和段控件的背景图像之间会出现一个空格。

这是显示空格的屏幕截图

在此处输入图像描述

这是我用来设置分段图像的代码

UIImage *selectedImage = [[UIImage imageNamed:@"segcontrol_selectround.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 10)];
UIImage *unselectedImage = [[UIImage imageNamed:@"segcontrol_unselectround.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 10)];
UIImage *leftSelected = [UIImage imageNamed:@"segcontrol_leftselected.png"];
UIImage *rightSelected = [UIImage imageNamed:@"segcontrol_rightselected.png"];
UIImage *neitherSelected = [UIImage imageNamed:@"segcontrol_bothunselected.png"];

[segment setBackgroundImage:unselectedImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[segment setBackgroundImage:selectedImage forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[segment setDividerImage:leftSelected forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[segment setDividerImage:rightSelected forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[segment setDividerImage:neitherSelected forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

我检查了所有的分隔线图像,它们都是相同的宽度并且不包含任何透明像素。

如何从分段控件中删除这些空格?

4

1 回答 1

3

确保用于分隔线( 、 和 )的图像leftSelected宽度rightselected相同neitherselected。通常是因为neitherselected中间的线比其他线宽 1pt。他们都需要是一样的!

于 2012-06-12T18:22:01.487 回答