I\'m writing in Objective-C.
How can I add a degree sign to a string? I know its unicode: 00B0
and UTF8: C2 B0
.
Just found this very helpful answer but it can even be abbreviated to the following (self explanatory):
NSString *temperature = @"65\u00B0";
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;
Use the string literal: \u00B0
. For Unicode characters, it will always be "\u" followed by the character code.
NSString *temperature = [NSString stringWithFormat:@"65%@", @"\u00B0"];
This is how you would do it using Swift:
var temperature = "65\u{00B0}" // degree symbol