I am trying to create a small indicator inside of a UIButton. Ive placed a custom view and changed the custom class in Interface builder to be my class. Ive then created an IBOutlet of the same type and connected them in interface builder as well.
My subclass then looks like this:
- (UIView *)initWithNumber:(NSInteger *)number
{
self = [super initWithFrame:CGRectMake(0, 0, 34, 17)];
if (self) {
[self setBackgroundColor:[UIColor blueColor]];
}
return self;
}
then in the main view I do:
self.indicatorControl = [indicatorControl alloc] initWithNumber:(NSNumber *)32];
But its not initializing the view and changing the background color when the view loads? Why doesn’t this happen? If I put the setBackgroundColor method call in awakeFromNib it works, but I want it to initialize and return my view when I call my initialization. It seems like this should work.
If you keep the IBOutlet there interface builder will re-initialize your button, overwriting your in-code button creation. Do you want to initialize the button in code or interface builder?
I would suggest:
Code: de-link the button from interface builder and put code in viewDidLoad of parent view controller
Interface builder: set the background to blue in interface builder or perform initialization in awakeFromNib