문제

When setting the tint color of a UISegmentedControl using the Appearance API, the color of the text in each unselected segment takes the color of the UILabel instead only after switching tabs.

A sample program to test this (screenshots below):

  • Load the program and look at the first tab. Everything is normal, the labels are red and the segments are blue.
  • Switch away to the second tab, everything is still fine.
  • Switch back to the first tab, you will see that the segments have changed to be red instead of blue like they should.

App was just loaded, everything is fine:

App was just loaded, everything is fine.

After switching tabs, color is wrong:

After switching tabs, color is wrong.

Code responsible (in the app delegate for testing, but happens elsewhere):

[[UILabel appearance] setTextColor:[UIColor redColor]];
[[UISegmentedControl appearance] setTintColor:[UIColor blueColor]];

I have sent this information to Apple in a bug report. They asked for a sample project, but I haven't gotten an answer yet. This only shows up on IOS 7.1. On 7.0, this doesn't happen.

Are there any suggestions or temporary fixes that would resolve this? It makes my app look bad even though I don't think it's my fault (the red is just to test, that would make anybody's app look bad). I have tried setting controls manually by setting the tint of the specific control instead of using the appearance API, but the problem is still there.

도움이 되었습니까?

해결책

As discussed in the comments, use [[UILabel appearanceWhenContainedIn:[UISegmentedControl class], nil] setTextColor:[UIColor blueColor]]; to set the appearance of the internal label contained in a segment control.

다른 팁

Per the Apple documentation: Setting the tintColor property by using the appearance proxy APIs is not supported in iOS 7.

iOS 7 UI Transition Guide

You can also specify text attributes like of UISegmentedControl like font, using setTitleTextAttributes:forState.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top