自定义分段控制无法正常工作

时间:2013-10-10 07:36:31

标签: iphone ios uiimage uisegmentedcontrol

我想自定义我应用的UISegmentControl,并使用以下代码:

UIImage *segmentSelected = [UIImage imageNamed:@"segcontrol_sel.png"];
UIImage *segmentUnselected = [UIImage imageNamed:@"segcontrol_uns.png"];
UIImage *segmentSelectedUnselected = [UIImage imageNamed:@"segcontrol_sel-uns.png"];
UIImage *segUnselectedSelected = [UIImage imageNamed:@"segcontrol_uns-sel.png"];
UIImage *segmentUnselectedUnselected = [UIImage imageNamed:@"segcontrol_uns-uns.png"];

[[UISegmentedControl appearance] setBackgroundImage:segmentUnselected
                                               forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setBackgroundImage:segmentSelected
                                               forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];

[[UISegmentedControl appearance] setDividerImage:segmentUnselectedUnselected
                                 forLeftSegmentState:UIControlStateNormal
                                   rightSegmentState:UIControlStateNormal
                                          barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:segmentSelectedUnselected
                                 forLeftSegmentState:UIControlStateSelected
                                   rightSegmentState:UIControlStateNormal
                                          barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance]
     setDividerImage:segUnselectedSelected
     forLeftSegmentState:UIControlStateNormal
     rightSegmentState:UIControlStateSelected
     barMetrics:UIBarMetricsDefault];

我从我的应用程序中获得了以下图片

First Picture

Second Picture

Third Picture

Forth Picture

我使用了几种方法来纠正像CGImages和Resizable Images这样的问题,但没有一种方法有效!问题是什么?我该如何解决?

1 个答案:

答案 0 :(得分:0)

我认为你应该看看下面的链接

http://idevrecipes.com/2010/12/13/wooduinavigation/

此处还有一个演示代码

https://github.com/xhan/PlutoLand