Question

Is there a documented Lifecycle for a UIControl somewhere?

Here's why I ask:

Suppose I have a UITextField. I could easily wire up a button that changes the border color like so:

myTextField.layer.borderColor = [[UIColor redColor] CGColor];

Now suppose I have a custom control that's a subclass of UIControl. That same code will not change the border color unless I also issue setNeedsLayout, like so:

[myControl setNeedsLayout];

Is there an event method somewhere that I need to implement to make this work without the setNeedsLayout?

Was it helpful?

Solution

For future generations, here's how I solved the problem on my own.

In my .h file:

@property (nonatomic, strong, setter = setBorderColor:) UIColor *borderColor;

In my .m file:

- (void)setBorderColor:(UIColor *)clr {
    borderColor = clr;
    myControl.layer.borderColor = borderColor.CGColor;
}

Works like a charm.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top