I recommend adding a UILabel as a subview of the button instead of an image, that way you can programmatically change it by using NSNotificationCenter from anywhere in your app.
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(updateButtonLabel:)
name:@"UpdateButtonLabel" object:nil];
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]
button.frame = CGRectMake(0, 0, 35, 35);
[button addTarget:self action:@selector(buttonMethods:) forControlEvents:UIControlEventTouchUpInside];
[button setTintColor:[UIColor companyBlue]];
[button setTitle:@"Button" forState:UIControlStateNormal];
self.buttonLabel = [[UILabel alloc]initWithFrame:CGRectMake(18,-7,18,18)];
self.buttonLabel.textColor = [UIColor whiteColor];
self.buttonLabel.backgroundColor = [UIColor companyRed];
self.buttonLabel.font = [UIFont systemFontOfSize:13.0];
self.buttonLabel.layer.cornerRadius = 9;
self.buttonLabel.layer.masksToBounds = YES;
self.buttonLabel.textAlignment = NSTextAlignmentCenter;
self.buttonLabel.text = @"!";
[button addSubview:self.buttonLabel];
}
- (void)updateButtonLabel:(NSNotification *)notification
{
NSString *labelString = notification.object;
// Post a notification from any view controller with a string with no characters to hide the label:
if (newString.length < 1)
{
self.buttonLabel.hidden = YES;
}
else
{
self.buttonLabel.text = labelString;
}
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}