-1

我目前正在创建一个应用程序,显示用户对他的视频有多少喜欢/不喜欢。我希望我喜欢/不喜欢的文字有 0.5 alpha。这就是我的代码的样子

我的代码看起来像这样,所以我的问题是如何使“喜欢/不喜欢”文本具有 0.5 alpha?

self.ratingLabel.text = @"%i likes %i dislikes", likes, dislikes;
4

1 回答 1

0

首先创建一个 0.5 作为 alpha 分量的颜色,形成一个现有的颜色:

UIColor* color= [someColor colorWithAlphaComponent: 0.5];

或从头开始:

UIColor* color= [UIColor colorWithRed: red green: green blue: blue alpha: 0.5];

然后您必须创建一个属性字符串并将其设置为标签的属性文本。前景色的属性是NSForegroundColorAttributeName

NSString* text= [NSString stringWithFormat: @"%i likes %i dislikes", likes, dislikes];
self.ratingLabel.attributedText= [[NSAttributedString alloc]initWithString: text attributes: @{ NSForegroundColorAttributeName : color}];
于 2013-07-11T22:48:23.730 回答