segmentedControl和UIAppearance代理的图形问题

时间:2012-02-15 12:15:03

标签: graphics ios5 proxy uisegmentedcontrol appearance

我在titleBar中有一个带有segmentedControl的应用程序,用于在3个导航控制器之间切换。我正在使用新的appearence代理方法来设置此segmentedControl的样式(下面的代码)。但是,似乎有一些我无法弄清楚的错误。当我潜入其中一个导航控制器然后导航回根(然后再次在顶部栏中显示segmentedControl)时,它会出现。当发生这种情况时,分隔符图形会在屏幕截图中看到混乱(第一个显示它看起来像什么)。

有没有人遇到类似的东西,知道如​​何解决它?

设置外观的代码是:

  UIImage *segmentSelected            = [[UIImage imageNamed:@"sel"]      resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
UIImage *segmentUnselected          = [[UIImage imageNamed:@"uns"]      resizableImageWithCapInsets:UIEdgeInsetsMake(0, 3, 0, 3)];
UIImage *segmentSelectedUnselected  = [[UIImage imageNamed:@"sel-uns"]  resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
UIImage *segUnselectedSelected      = [[UIImage imageNamed:@"uns-sel"]  resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
UIImage *segmentUnselectedUnselected = [[UIImage imageNamed:@"uns-uns"]  resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];

[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setBackgroundImage:segmentUnselected forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setBackgroundImage:segmentSelected forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setDividerImage:segmentUnselectedUnselected forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setDividerImage:segmentSelectedUnselected forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setDividerImage:segUnselectedSelected forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setContentPositionAdjustment:UIOffsetMake(8, 0) forSegmentType:UISegmentedControlSegmentLeft barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearanceWhenContainedIn:[UINavigationBar class], nil] 
      setContentPositionAdjustment:UIOffsetMake(-8, 0) forSegmentType:UISegmentedControlSegmentRight barMetrics:UIBarMetricsDefault];

应该是什么样子:

what it is supposed to look like

它的样子:

enter image description here

3 个答案:

答案 0 :(得分:0)

我通过外观使用了UINavigatorBar的backgroundImage,并注意到使用该方法和UISplitViewController / UIPopoverController将整个导航栏移动到内容区域。所以你只看到深蓝色边框,定制的导航栏位于边框正下方,看起来非常奇怪。

没有帮助,但这可能是一个真正的错误?!

答案 1 :(得分:0)

我遇到了同样的问题。最终我最终使用1px宽分频器图像 - >然后问题就消失了。

答案 2 :(得分:0)

请确保您在应用程序委托中使用此函数didfinishLaunching应用于所有视图控制器。我有相同的问题图像重叠。在一个地方使用它解决问题。尝试[uiview class]而不是[uinavigationBar class]