Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
UISlider 用に制御されるラベルがあります。スライダーの途中まで行くと、.50 が表示されます。その .50 を 50% に変更するにはどうすればよいですか? 本当にありがとう!
私のスライダーコード:
- (IBAction) sliderValueChanged:(UISlider *)sender { tipPercentLabel.text = [NSString stringWithFormat:@" %.2f", [sender value]]; }
UISlider は 0.0 と 1.0 の間の分数です。
では、次のようなものはどうでしょうか。
tipPercentLabel.text = [NSString stringWithFormat:@" %f%%", ([sender value] * 100)];
フォーマット文字列の " %%" は、印刷されるパーセント文字を示します。フォーマット文字列が少しずれている可能性があります(乗算された値を整数にキャストし、「%d%%」を使用する可能性があります)。
%%
%d%%