I use NSAttributedString
to generate a string with two different sizes. By default, its bottom alignment looks like this:
Here is a working example to vertically align smaller text using NSBaselineOffsetAttributeName
.
NSString *bigString = @"BIG";
NSString *smallString = @"Small String";
NSString *fullString = [NSString stringWithFormat:@"%@ %@", bigString, smallString];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:fullString];
NSRange bigStringRange = NSMakeRange(0, bigString.length);
NSRange smallStringRange = NSMakeRange(bigStringRange.length, smallString.length);
[string beginEditing];
//Set big string font and size
[string addAttribute:NSFontAttributeName
value:[UIFont systemFontOfSize:28.0]
range:bigStringRange];
//set small string font and size
[string addAttribute:NSFontAttributeName
value:[UIFont systemFontOfSize:18.0]
range:smallStringRange];
//Set small string baseline offset
[string addAttribute:NSBaselineOffsetAttributeName
value:[NSNumber numberWithFloat:3.0] //adjust this number till text appears to be centered
range:smallStringRange];
[string endEditing];