0

我有一个UISegmentedControl并且我正在尝试设置一个分隔符图像。图像是黑色的,大约 2 像素宽。

UIImage *divider = [UIImage imageNamed:@"ZSDivider.png"];
[self.segmentedControl setDividerImage:divider forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[self.segmentedControl setDividerImage:divider forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[self.segmentedControl setDividerImage:divider forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:UIBarMetricsDefault];

我不想要任何花哨的分隔线,只是每个州都有一条黑线,但它根本没有出现。

任何想法我做错了什么?

4

2 回答 2

1

您的分隔线图像与分段控件的高度相同吗?如果我没记错的话,如果分隔线与控件高度不匹配,UISegmentedControl 会出现问题。

于 2012-11-01T01:20:52.777 回答
0

你确定 " divider" 和 " self.segmentedControl" 不为空吗?

这看起来是一个很好的错误检查机会:

UIImage *divider = [UIImage imageNamed:@"ZSDivider"];
if(divider)
{
    if(self.segmentedControl)
    {
        [self.segmentedControl setDividerImage:divider forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        [self.segmentedControl setDividerImage:divider forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        [self.segmentedControl setDividerImage:divider forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
    } else {
        NSLog( @"segmentedControl is NULL");
    }
} else {
    NSLog( @"divider image is NULL");
}
于 2012-11-01T00:53:39.277 回答