How can I represent the Degree Fahrenheit symbol in an NSString? The following code will produce a degree symbol and then the capital letter F, but is there an actual as Fahrenheit itself? Similarly, is there one for Degree Celsius?
NSString *fahrenheit = [NSString stringWithFormat:@"%@F", @"\u00B0"]; NSString *celsius = [NSString stringWithFormat:@"%@C", @"\u00B0"]; 22 Answers
Your code is correct, and that is how you would represent the two temperature ranges. It can be cut down slightly as you don't need to use stringWithFormat:
NSString *fahrenheit = @"\u00B0F"; NSString *celsius = @"\u00B0C"; But you might use stringWithFormat to format the actual temperatures along with the symbols etc:
float tempInFahrenheit = 23.4f; float tempInCelsius = 56.8f; NSString *fahrenheit = [NSString stringWithFormat:@"%f \u00B0F", tempInFahrenheit]; NSString *celsius = [NSString stringWithFormat:@"%f \u00B0C", tempInCelsius]; 0 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; ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJoaW1pYmiEcoGOnZygqpWaeqetx6ucp6CVnsFur8SlqqKto2LAurnBqKOsZZGosKq1jKeqrKyinruo