所以在我自定义 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];