华氏度/摄氏符号ASCII NSString

时间:2014-06-09 15:38:34

标签: ios objective-c nsstring

如何在NSString中表示 Degree Fahrenheit 符号?下面的代码将产生一个度数符号,然后是大写字母F,但实际上是华氏温度吗?同样,是否有一个摄氏度

NSString *fahrenheit = [NSString stringWithFormat:@"%@F", @"\u00B0"];
NSString *celsius = [NSString stringWithFormat:@"%@C", @"\u00B0"];

2 个答案:

答案 0 :(得分:3)

您的代码是正确的,这就是您代表两个温度范围的方式。它可以稍微减少,因为您不需要使用stringWithFormat

NSString *fahrenheit = @"\u00B0F";
NSString *celsius = @"\u00B0C";

但您可以使用stringWithFormat格式化实际温度以及符号等:

float tempInFahrenheit = 23.4f;
float tempInCelsius = 56.8f;
NSString *fahrenheit = [NSString stringWithFormat:@"%f \u00B0F", tempInFahrenheit];
NSString *celsius = [NSString stringWithFormat:@"%f \u00B0C", tempInCelsius];

答案 1 :(得分:-1)

    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"80\u00b0c"];
        [attributedString setAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"Helvetica-light" size:40.0]
                                          , NSBaselineOffsetAttributeName : @22} range:NSMakeRange(2, 2)];
        //asign this as a 
examplelabel.attributedtext = attributedString;