Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Shouldn't <code>drawRect:</code> be called automatically for the animation to update for the new <code>tintColor</code>?</p> <p>I've made a demo application that has three controls in the main view controller. The first is a button that brings up a standard action sheet. The second is a button that's there for observation (the tapped button is hard to compare to during the animation). The third is a custom <code>UIView</code> subclass that simply draws a rectangle of the view's <code>tintColor</code>. When <code>tintColorDidChange</code> is called, I call <code>setNeedsDisplay</code>, which in turn will call <code>drawRect:</code>.</p> <p>I created a new application with one view controller:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [[UIApplication sharedApplication] keyWindow].tintColor = [UIColor blueColor]; // Button to bring up action sheet UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = (CGRect){10,30,300,44}; [button setTitle:@"Present Action Sheet" forState:UIControlStateNormal]; [button addTarget:self action:@selector(didTapPresentActionSheetButton:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; // Another button for demonstration UIButton *anotherButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; anotherButton.frame = (CGRect){10,90,300,44}; [anotherButton setTitle:@"Another Button" forState:UIControlStateNormal]; [self.view addSubview:anotherButton]; // Custom view with tintColor TESTCustomView *customView = [[TESTCustomView alloc] initWithFrame:(CGRect){10,150,300,44}]; [self.view addSubview:customView]; } - (void)didTapPresentActionSheetButton:(id)sender { UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:@"Action Sheet" delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete" otherButtonTitles:@"Other", nil]; [as showInView:self.view]; } </code></pre> <p>where <code>TESTCustomView</code> is a <code>UIView</code> subclass with implementation as follows:</p> <pre><code>- (void)drawRect:(CGRect)rect { NSLog(@"Drawing with tintColor: %@", self.tintColor); // Drawing code [super drawRect:rect]; CGContextRef c = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(c, self.tintColor.CGColor); CGContextFillRect(c, rect); } - (void)tintColorDidChange { [self setNeedsDisplay]; } </code></pre> <p>Running this application in the simulator shows that the custom view's tintColor is automatically animated with the standard <code>UIButton</code> instances in the view controller.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload