So I'm trying to change a button's title after it has been added into another view. A gave it a tag so I can call it but it's not working.
Button code
Method to change the title
The warning is 'UIView' may not respond to 'SetTitle:forState'
Which is true... I'm trying to target the button and not the view.
thanks.
Button code
Code:
//button
CGRect frame = CGRectMake(100.0, 70.0, 100.0, 35.0);
UIImage *blueImage = [UIImage imageNamed:@"blue_button.png"];
UIImage *blueButtonImage = [blueImage stretchableImageWithLeftCapWidth:7 topCapHeight:0];
UIButton *btn = [[UIButton alloc] initWithFrame:frame];
[btn setTitle:@"CaSO4" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlEventTouchDown];
btn.titleLabel.font = [UIFont boldSystemFontOfSize:12.0];
[btn setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 0.0, 0.0, 10.0)];
[btn setBackgroundImage:blueButtonImage forState:UIControlStateNormal];
btn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[btn addTarget:self action:@selector(slideButton:) forControlEvents:UIControlEventTouchUpInside];
btn.tag = 102;
[self.view addSubview:btn];
[btn release];
Method to change the title
Code:
- (void)setButton:(NSString *)label
{
[[self.view viewWithTag:102] setTitle:label forState:UIControlStateNormal];
}
The warning is 'UIView' may not respond to 'SetTitle:forState'
Which is true... I'm trying to target the button and not the view.
thanks.