1 UIImage *segmentSelected = [[UIImage imageNamed:@"segcontrol_sel.png"] 2 resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)]; 3 UIImage *segmentUnSelected = [[UIImage imageNamed:@"segcontrol_uns.png"] 4 resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)]; 5 UIImage *segmentSelectedUnselected = [[UIImage imageNamed:@"segcontrol_sel-uns.png"] 6 resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)]; 7 UIImage *segmentUnSelectedSelected = [[UIImage imageNamed:@"segcontrol_uns-sel.png"] 8 resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)]; 9 UIImage *segmentUnSelectedUnSelected = [[UIImage imageNamed:@"segcontrol_uns-uns.png"]10 resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)];11 12 [self.seg setBackgroundImage:segmentUnSelected // 非选中状态背景图13 forState:UIControlStateNormal14 barMetrics:UIBarMetricsDefault];15 [self.seg setBackgroundImage:segmentSelected // 选中状态背景图16 forState:UIControlStateSelected17 barMetrics:UIBarMetricsDefault];18 19 [self.seg setDividerImage:segmentUnSelectedUnSelected // 设置分割部分背景图,二侧都是非选中状态时20 forLeftSegmentState:UIControlStateNormal21 rightSegmentState:UIControlStateNormal22 barMetrics:UIBarMetricsDefault];23 24 [self.seg setDividerImage:segmentSelectedUnselected // 设置分割部分背景图,左边为选中状态,右边为非选中状态时25 forLeftSegmentState:UIControlStateSelected26 rightSegmentState:UIControlStateNormal27 barMetrics:UIBarMetricsDefault];28 29 [self.seg setDividerImage:segmentUnSelectedSelected // 设置分割部分背景图,左边为非选中状态,右边为选中状态30 forLeftSegmentState:UIControlStateNormal31 rightSegmentState:UIControlStateSelected32 barMetrics:UIBarMetricsDefault];