我使用背景和分隔图像来自定义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];
我检查了所有分割器图像,它们的宽度都相同,并且不包含任何透明像素。
如何从分段控件中删除这些空格?
答案 0 :(得分:3)
确保用于分隔线的图像(leftSelected
,rightselected
和neitherselected
)宽度相同。通常因为neitherselected
在中间有一条线,它比其他线宽1pt。他们都需要一样!