سؤال

I'm trying to make a UI Button a toggle button by using this code:

- (void)tapButton:(id)sender{
    UIButton *button = sender;
    if (!button.selected){
        [self performSelector:@selector(highlight:) withObject:button afterDelay:0.0];
    }else{
        [self performSelector:@selector(removeHighlight:) withObject:button afterDelay:0.0];
    }
}

- (void)highlight:(UIButton *)button{
    button.selected = !button.selected;
    button.highlighted = YES;
}

- (void)removeHighlight:(UIButton *)button{
    button.selected = !button.selected;
    button.highlighted = NO;
}

However, I'm getting a weird artefact when the button is in selected mode.

Not selected:

enter image description here

Selected:

enter image description here

هل كانت مفيدة؟

المحلول

Just make the button type to be "custom" instead of "system". I guess this weird bug is related to the new Tint feature on iOS7. It's probably buggy because your title property is an empty string @"".

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top