- (void)setStrokeLabel:(BOOL)strokeLabel
{
_strokeLabel = strokeLabel;
if (_strokeLabel) {
_timer = [NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:@selector(setStrokeThrough) userInfo:nil repeats:NO];
} else {
[self cancelStrokeThrough];
}
}
- (void)setStrokeThrough
{
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:self.attributedText];
for (NSUInteger i = 1; i <= [attributedString length]; i++) {
[attributedString addAttribute:NSStrikethroughStyleAttributeName
value:[NSNumber numberWithInt:1]
range:NSMakeRange(0, i)];
self.attributedText = attributedString;
}
}
- (void)cancelStrokeThrough
{
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:self.attributedText];
[attributedString removeAttribute:NSStrikethroughStyleAttributeName
range:NSMakeRange(0, [attributedString length])];
self.attributedText = attributedString;
}
我想制作动画strike-through
,比如 todo done 动画。当我为它设置定时器时,定时器只处理如何逐个字母地显示笔触?