Degree Fahrenheit/Celsius Symbols ASCII NSString

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"];
2

2 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;

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like