How I can set UIImage in the normal state and set title in the selected state in my UIButton?
Hi, I try to set a UIImage in the normal state of UIButton, but when set an UImage in normal state this change the title of UIButton in the selected state changing the title for the image . I am using
myButton setTitle:content forState:UIControlStateSelected
in the state selected.
How I can set UIImage in the normal state and set title in the selected state in my UIButton?
PDT: sorry for my english!.
Try This:
BOOL selected;
-(IBAction)btnClicked:(UIButton *)sender{
if(selected)
{
[chkBtn setTitle:@"selected" forState:UIControlStateNormal];
chkImage.image=[UIImage imageNamed:@" "];
NSLog(@"%@",chkBtn.titleLabel);
selected=NO;
}
else
{
[chkBtn setTitle:@" " forState:UIControlStateNormal];
chkImage.image=[UIImage imageNamed:@"button_minus_pink.png"];
selected=YES;
}
}
// set with UIColor
[self.button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
// set with UIImage
[self.button setBackgroundImage:[UIImage imageNamed:@"BlackRightBtn.png"] forState:UIControlStateNormal];
For Button Selected
if (self.button.isSelected == YES)
{
[self.button setTitle:@"Your_ButtonTitle" forState:UIControlStateNormal];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With