Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom UIControl with UILabel dimming on tint color change

In case of UISegmentedControl, once a popover or alert is present, the Control dims to grey (desaturates the tint color)

I'am building my own UIControl subclass, which uses a UILabel as a subview

i want to dim (desaturate) the text color of the UILabel, same way as by UISegmentedControl or (UIButton...)

like image 671
Peter Lapisu Avatar asked Jan 09 '14 11:01

Peter Lapisu


1 Answers

Look at the tintColor and tintAdjustmentMode properties on UIView (available since iOS 7) and the tintColorDidChange method.

If you override them in your custom view you can respond to being dimmed out.

As the iOS 7 UI Transitioning Guide says:

When an alert or action sheet appears, iOS 7 automatically dims the tint color of the views behind it. To respond to this color change, a custom view subclass that uses tintColor in its rendering should override tintColorDidChange to refresh the rendering when appropriate.

The solution may look like this :

- (void)tintColorDidChange {

    self.titleLabel.textColor = self.tintColor;

}
like image 189
David Rönnqvist Avatar answered Sep 28 '22 05:09

David Rönnqvist