如何在iOS中将以下字符‡,†,*作为上标追加到NSString [英] How to append the following characters ‡, †, * as superscript to NSString in iOS

查看:42
本文介绍了如何在iOS中将以下字符‡,†,*作为上标追加到NSString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在iOS中的NSString后面添加以下字符‡, †, *作为上标.需要你的帮助.我使用以下 http://en.wikipedia.org/wiki/General_Punctuation_(Unicode_block)链接,但它们附加到NSString,但是我希望它们作为上标

I need append the following characters ‡, †, * as superscript to NSString in iOS . Need your help. I use the following http://en.wikipedia.org/wiki/General_Punctuation_(Unicode_block) link but they are appending to NSString , But i want them as superscript

推荐答案

尝试使用此方法.并且您需要#import <CoreText/CTStringAttributes.h>.此代码仅适用于iOS6或更高版本.

Try to use this one. And you need to #import <CoreText/CTStringAttributes.h>. This code works only in iOS6 or later version.

UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 200, 40)];
NSString *infoString=@"X2 and H20 A‡ B† C*";

NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:infoString];

[attString addAttribute:(NSString *)kCTSuperscriptAttributeName value:@1 range:NSMakeRange(1, 1)];
[attString addAttribute:(NSString *)kCTSuperscriptAttributeName value:@-1 range:NSMakeRange(8, 1)];
[attString addAttribute:(NSString *)kCTSuperscriptAttributeName value:@1 range:NSMakeRange(12, 1)];
[attString addAttribute:(NSString *)kCTSuperscriptAttributeName value:@1 range:NSMakeRange(15, 1)];
[attString addAttribute:(NSString *)kCTSuperscriptAttributeName value:@1 range:NSMakeRange(18, 1)];

lbl.attributedText = attString;

[self.view addSubview:lbl];

输出

我希望这会对您有所帮助

I hope this will help you

这篇关于如何在iOS中将以下字符‡,†,*作为上标追加到NSString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆