0

Under IOS7, I've defined a UISegmentedControl in the interface builder and use the following code to customize it:

 segconOptions.layer.cornerRadius = 20.0;
 segconOptions.layer.masksToBounds = YES;

 //[segconOptions setTintColor:[UIColor whiteColor]];
 [segconOptions setTintColor:[UIColor blueColor]];  //temp change for graphics issue

 [segconOptions setBackgroundColor:[UIColor clearColor]];
 [segconOptions setAlpha:1.0];

 [segconOptions setBackgroundImage:[UIImage imageNamed:@"blue.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
 [segconOptions setBackgroundImage:[UIImage imageNamed:@"yellow.png"] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];

I was expecting the text to appear over the background images(white text over blue, red text over yellow). However, instead, have these large squares around the text. I changed the font color to blue for the non-selected cells to make the text readable in this screenshot:

Undesired whiteboxes around text

How do I display the button title text over my custom background image, without these white boxes around the text? I assume I'm missing something obvious, but I've been searching all day and keep coming up with nothing. Thanks in advance!

Thunk
  • 3,829
  • 7
  • 24
  • 43

1 Answers1

0

I can only think that the problem is because of some unusual thing you're doing to the segmented control. When I set the background image of a segmented control and set the titles of the segments, I don't get any white rectangle - see the attached screen shot.

enter image description here

I tried to imitate your code (note the rounded corners) but I couldn't get any white rectangle. Maybe the white rectangle is part of your blue.png image! (Note that you should be using a resizeable image here, by the way.)

matt
  • 447,615
  • 74
  • 748
  • 977
  • That doesn't work either. The image appears in the middle of each segment with same white square around it. It wouldn't really be a viable workaround, anyway, since the setImage call subsequently hides the button text. – Thunk Apr 20 '14 at 03:01
  • Okay, I've erased that answer and given a new one. As you can see from the screen shot, I don't get any white squares, so I have to think that you're causing them in some way. – matt Apr 20 '14 at 05:09
  • Thanks for confirming that my expected behavior is indeed correct. After much experimentation, it turns out to be some problem with the background images I'm using. I replaced them with two new images, and it's working correctly now. >< Anyway, I'm marking your answer as correct since it put me on the right debugging path. Thanks! – Thunk Apr 21 '14 at 04:16