0

I have a label that is controlled for a UISlider. When I get half way with the slider it shows .50. How can I change that .50 to 50%? Thanks so much!

My slider code:

- (IBAction) sliderValueChanged:(UISlider *)sender {
    tipPercentLabel.text = [NSString stringWithFormat:@" %.2f", [sender value]];
}
4

1 回答 1

2

UISlider 是介于 0.0 和 1.0 之间的分数。

那么像这样的东西怎么样:

tipPercentLabel.text = [NSString stringWithFormat:@" %f%%", ([sender value] * 100)];

格式字符串中的“ %%”表示要打印的百分比字符。我可能在格式字符串中有点偏离(可能将相乘的值转换为整数并使用“ %d%%”)。

于 2013-06-12T23:18:31.087 回答