0

所以在我自定义 UISegmentedControl 之后,一切都搞砸了,标签移动了,有一条我不知道它来自哪里的白色垂直线。分隔线也偏离了中心,我检查过黑线在 80px 图像的 40-41px 处,所以它必须居中。想我做错了还是以前有人经历过?

定制前: 在此处输入图像描述

定制后:

注意:分隔图像是彼此的水平翻转。

在此处输入图像描述

在此处输入图像描述

代码:

UIImage *un_sel = [UIImage imageNamed:@"divider-un-sel"];
UIImage *sel_un = [UIImage imageNamed:@"divider-sel-un"];

[_segmentControl setDividerImage:un_sel forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:UIBarMetricsDefault];

[_segmentControl setDividerImage:sel_un forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

UIImage *normal = [[UIImage imageNamed:@"segment-normal"] stretchableImageWithLeftCapWidth:20 topCapHeight:0];
UIImage *selected = [[UIImage imageNamed:@"segment-selected"] stretchableImageWithLeftCapWidth:20 topCapHeight:0];

[_segmentControl setBackgroundImage:normal forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[_segmentControl setBackgroundImage:selected forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
4

1 回答 1

0

通过使用解决了问题

[[UIImage imageNamed:@"segment-normal"]  resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)];

代替stretchableImageWithLeftCapWith:topCapHeight

于 2013-08-27T11:45:13.843 回答