3

I have an app with a segmentedControl in the titleBar, which is used to switch between 3 navigation controllers. I am using the new appearence proxy methods to style this segmentedControl (code below). However, there seems to be some sort of bug that I cannot figure out. It appears when I dive into one of the navigation controllers and then navigate back to the root (which then shows the segmentedControl in the top bar again). When that happens the divider graphics get messed up as you can see in the screenshot (the first one shows what it's supposed to look like).

Has anyone encountered anything similar and knows how to fix it?

My code to set the appearence is:

  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:

what it is supposed to look like

what it looks like:

enter image description here

Sebastian
  • 2,889
  • 4
  • 34
  • 37

3 Answers3

0

I've had the same issue. Eventually I ended up using a 1px wide divider image -> then the issue disappeared.

ARsteve
  • 436
  • 2
  • 4
0

Please make sure you are using this in app delegate didfinishLaunching applied for all the view controller.I have the same problem image overlapped . use it in one place problem resolved .Try with [uiview class] instead of [uinavigationBar class]

gomathi
  • 11
  • 2
0

I've used a backgroundImage for UINavigatorBar via appearance and noticed that using that approach together with a UISplitViewController/UIPopoverController the whole navigation bar is moved into the content area. So you just see the darkblue border and the customized Navigation bar is positioned right below the border looking very strange.

No help for you but it might be a real bug?!

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
Bernd Rabe
  • 790
  • 6
  • 23