[英]Animate UILabel to Change Colour?
我想讓我的UILabel
的文本稱為coloursLabel
更改文本顏色。 我嘗試了以下方法作為另一個SO答案的建議(盡管是backgroundColor
),但它仍然沒有改變。 我想念一些愚蠢的東西嗎?
UILabel *coloursLabel = [[UILabel alloc] init];
coloursLabel.text = @"This sentence is colourful!";
[coloursLabel sizeToFit];
coloursLabel.center = self.view.center;
coloursLabel.frame = CGRectOffset(coloursLabel.frame, timeForPage(6), 0);
[UIView animateWithDuration:2.0 animations:^{
coloursLabel.textColor = [UIColor greenColor];
coloursLabel.textColor = [UIColor redColor];
coloursLabel.textColor = [UIColor blueColor];
coloursLabel.textColor = [UIColor yellowColor];
coloursLabel.textColor = [UIColor blackColor];
} completion:NULL];
coloursLabel
顯示正確的文本,但文本為黑色。
任何幫助將非常感激!
UILabel的textColor不能設置動畫。 您可以使用CATextLayer作為遮罩並為其圖層的backgroundColor設置動畫,從而編寫自己的Label類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.