Skip to content

Toggle Tag Method #6

@AlexHedley

Description

@AlexHedley

What would be the best way to have a toggle function so you can change the colour of the tag when you select, deselect it?

#define selectedColor [UIColor colorWithRed: 255.0/255.0 green: 128.0/255.0 blue: 0 alpha: 1.0]
#define deselectedColor [UIColor colorWithRed: 255.0/255.0 green: 0 blue: 0 alpha: 1.0]

From your demo in the viewDidLoad I've amended the block

[self.tagListView addTagsAccordingToDataSourceArray:@[@"from", @"array", @"too"] withOnTapForEach:^(TagView *tagView) {
        if ([tagView.backgroundColor isEqual:selectedColor]) {
            tagView.backgroundColor = deselectedColor;
        } else {
            tagView.backgroundColor = selectedColor;
        }
}

The background colour is set in IB but when compared it doesn't match.

If I add to viewDidLoad

self.tagListView.tagBackgroundColor = selectedColor;

it works.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions