Yes, you could use the gesture with your UILabel
for highlighting text by either changing the background color or text color of your UILabel
.
You could also store the current state of your UILabel
using NSUserDefaults
, and read it back we user launch your application.
Declare an isLabelHighlighted
as BOOL for UILabel
state.
UITapGestureRecognizer* myLabelGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(LabelClicked:)];
[myLabelView setUserInteractionEnabled:YES];
[myLabelView addGestureRecognizer:myLabelGesture];
-(void)LabelClicked:(UIGestureRecognizer*) gestureRecognizer
{
if(isLabelHighlighted)
{
myLabelView.highlightedTextColor = [UIColor greenColor];
}
else
{
myLabelView.highlightedTextColor = [UIColor redColor];
}
}
To store state of your UILabel
.
[[NSUserDefaults standardUserDefaults] setBool:isLabelHighlighted forKey:@"yourKey"];
To access it, you should use below.
isLabelHighlighted = [[NSUserDefaults standardUserDefaults] boolForKey:@"yourKey"];