effetto tendone in uitableviewcells textlabel.text
-
05-07-2019 - |
Domanda
C'è un modo per realizzare qualcosa come l'effetto html Marquee per un uitableviewcells textlabel.text?
Soluzione
Dovrai implementarlo da solo usando un NSTimer. Dovresti scorrere i caratteri del tuo textLabel.text
prendendo uno dalla parte anteriore e aggiungendolo alla parte posteriore. Per farlo facilmente potresti usare un NSMutableString
che manipoleresti usando substringWithRange:
deleteCharactersInRange:
e appendString
, quindi imposta come textLabel.text
dopo ogni manipolazione di caratteri:
- (void)fireTimer
{
NSMutableString *mutableText = [NSMutableString stringWithString: textLabel.text];
//Takes the first character and saves it into a string
NSString *firstCharText = [mutableText substringWithRange: NSMakeRange(0, 1)];
//Removes the first character
[mutableText deleteCharactersInRange: NSMakeRange(0, 1)];
//Adds the first character string to the initial string
[mutableText appendString: firstCharText];
textLabel.text = mutableText;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow