I want my UIButton to display the highlighted state when I click on a button that is already selected.
Basically, in the selected state, I use the * .png image as my UIButton backgroundImage to give the pressed effect.
But if the button is already in the selected state. When I click on it again, I just donβt see the highlighted state, but it goes directly to the normal state!
Watch the problem β Video problems!
help me please
//0 init UIButton UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x, y, aSide, aSide)]; //1 Give it a backgroundColor [button setBackgroundColor:aColor]; [..] //2 Set titleLabel and its style [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [button setTitleColor:[UIColor redColor] forState:UIControlStateSelected]; [button setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted]; UIImage *shadowImage = [UIImage imageNamed:kBtnShadow]; shadowImage = [shadowImage stretchableImageWithLeftCapWidth:floorf(shadowImage.size.width/2) topCapHeight:floorf(shadowImage.size.height/2)]; [button setBackgroundImage:shadowImage forState: UIControlStateHighlighted]; [button setTitle:aLabel forState: UIControlStateNormal]; //3 Assign tag and Action [button setTag:tag]; [button addTarget:target action:a forControlEvents:UIControlEventTouchUpInside];
selected ios uibutton uicontrolevents
luca
source share