andreamazz / AMTagListView

UIScrollView subclass that allows to add a list of highly customizable tags.
MIT License
758 stars 110 forks source link

Enhancement: Changing textColor on the fly. #38

Closed PatrykKaczmarek closed 9 years ago

PatrykKaczmarek commented 9 years ago

Hey!

I have list of my tags. Every tag has 2 states: selected and deselected. I'm tracking selection of my tags in separate NSMutableArray. Of course when those 2 states have different colors (reversed). I noticed that I had send setNeedsLayout message to AMTagView object to redisplay textColor properly:

    self.selectedTags = [NSMutableArray array];

    [self.tagListView addTags:@[@"my tag", @"some tag"]];
    [self.tagListView setTapHandler:^(AMTagView *view) {

        BOOL contains = [self.selectedTags containsObject:[view tagText]];
        contains ? [self.selectedTags removeObject:[view tagText]] : [self.selectedTags addObject:[view tagText]];  // is there better way to track selected tags?

        if (contains) {
            [view setInnerTagColor:[UIColor whiteColor]];
            [view setTextColor:[UIColor redColor]];
        } else {
            [view setInnerTagColor:[UIColor redColor]];
            [view setTextColor:[UIColor whiteColor]];
        }
        [view setNeedsLayout]; // <-- here have to do it manually
    }];

My question is: Maybe it could be worth to override setTextColor method in AMTagView?

- (void)setTextColor:(UIColor *)textColor {
    _textColor = textColor;
    [self setNeedsLayout];
}
andreamazz commented 9 years ago

Good call :+1: You'll find the fix in version 0.8.1

PatrykKaczmarek commented 9 years ago

Thanks!