自定义UISegmentedControl

在页面中

 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:UIControlStateNormal
14                       barMetrics:UIBarMetricsDefault];
15     [self.seg setBackgroundImage:segmentSelected        // 选中状态背景图
16                         forState:UIControlStateSelected
17                       barMetrics:UIBarMetricsDefault];
18     
19     [self.seg setDividerImage:segmentUnSelectedUnSelected   // 设置分割部分背景图,二侧都是非选中状态时
20           forLeftSegmentState:UIControlStateNormal
21             rightSegmentState:UIControlStateNormal
22                    barMetrics:UIBarMetricsDefault];
23     
24     [self.seg setDividerImage:segmentSelectedUnselected    // 设置分割部分背景图,左边为选中状态,右边为非选中状态时
25           forLeftSegmentState:UIControlStateSelected
26             rightSegmentState:UIControlStateNormal
27                    barMetrics:UIBarMetricsDefault];
28     
29     [self.seg setDividerImage:segmentUnSelectedSelected    // 设置分割部分背景图,左边为非选中状态,右边为选中状态
30           forLeftSegmentState:UIControlStateNormal
31             rightSegmentState:UIControlStateSelected
32                    barMetrics:UIBarMetricsDefault];

 

 

posted @ 2013-02-18 15:12  diablo大王  阅读(6378)  评论(0编辑  收藏  举报