Objective c 我还有别的地方(我也很懒)。我已经更新了我的答案,包括一个例子。苏丹不需要道歉!!非常感谢你的片段。我正在研究它!DD+1@DavidDelMonte这已经相当详细了。如果您不了解这一点,请学习nsattributestring的一些示例。很早以前,当我开

Objective c 我还有别的地方(我也很懒)。我已经更新了我的答案,包括一个例子。苏丹不需要道歉!!非常感谢你的片段。我正在研究它!DD+1@DavidDelMonte这已经相当详细了。如果您不了解这一点,请学习nsattributestring的一些示例。很早以前,当我开,objective-c,ios7,uibutton,Objective C,Ios7,Uibutton,我还有别的地方(我也很懒)。我已经更新了我的答案,包括一个例子。苏丹不需要道歉!!非常感谢你的片段。我正在研究它!DD+1@DavidDelMonte这已经相当详细了。如果您不了解这一点,请学习nsattributestring的一些示例。很早以前,当我开始编程时,我就知道(别人教我的),最好的程序员都是懒惰的。也就是说,如果我们不需要的话,我们不会重新创造事物。所以,谢谢你的建议,这里有一些反馈:)我的学习风格是这样的,我从复制的代码中学到了很多东西。事实上,这比任何其他方法都重要。这就是我在


我还有别的地方(我也很懒)。我已经更新了我的答案,包括一个例子。苏丹不需要道歉!!非常感谢你的片段。我正在研究它!DD+1@DavidDelMonte这已经相当详细了。如果您不了解这一点,请学习
nsattributestring
的一些示例。很早以前,当我开始编程时,我就知道(别人教我的),最好的程序员都是懒惰的。也就是说,如果我们不需要的话,我们不会重新创造事物。所以,谢谢你的建议,这里有一些反馈:)我的学习风格是这样的,我从复制的代码中学到了很多东西。事实上,这比任何其他方法都重要。这就是我在60年代末学习COBOL的方式。在这里聪明人的帮助下,在YouTube上的孩子们的帮助下,我又开始学习了。“太好了!”大卫蒙特请接受我的道歉。我对那些盲目复制粘贴代码而不理解它的人有更多的经验。这就是为什么要避免解释那些在其他地方解释得更好的基础知识(我也很懒)。我已经更新了我的答案,包括一个例子。苏丹不需要道歉!!非常感谢你的片段。我正在研究它!DD+1
 if (button.tag == 200)
        [button setTitle: @"x\u00B3 + x\u00B2 + x\u00B9 + k" forState: UIControlStateNormal | UIControlStateHighlighted | UIControlStateSelected];
[NSString stringWithUTF8String:"foot\u00b2"];
UIBarButtonItem *btnOffer=[[UIBarButtonItem alloc] initWithTitle:[NSString stringWithUTF8String:"foot\u00b2"] style:UIBarButtonItemStylePlain target:self action:@selector(btnOffer_clicked)];

self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:34.0/255.0f green:182.0/255.0f blue:226.0/255.0f alpha:1.0];
[self.navigationItem setRightBarButtonItem:btnOffer];
#import <CoreText/CTStringAttributes.h>

// ...

NSMutableAttributedString *attributedTitle = [[NSMutableAttributedString alloc]initWithString:@"22"];

[attributedTitle addAttribute:(NSString*)kCTSuperscriptAttributeName value:@"1" range:NSMakeRange(1, 1)];

[button setAttributedTitle:attributedTitle forState:UIControlStateNormal];
 x² - U+00Bx2 -> X\u00B2
 x³ - U+00Bx3 -> X\u00B3
 x⁶ - U+207x6 -> X\u2076
[button setTitle:@"X\u00B2" forState:UIControlStateNormal];
[button setTitle:@"X\u00B3" forState:UIControlStateNormal];
[button setTitle:@"X\u2076" forState:UIControlStateNormal];
//input parameters
NSString *title = @"e";
NSString *superscript = @"x";
UIFont *font = [UIFont systemFontOfSize:20.0f];

//our buffer
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] init];

//just append the title and set its font
[attributedString appendString:title];        
NSRange titleRange = NSMakeRange(0, title.length);

[attributedString addAttribute:NSFontAttributeName
                         value:font
                         range:titleRange];

//append the superscript
[attributedString appendString:superscript];       
NSRange superscriptRange = NSMakeRange(title.length, superscript.length);

//start of the important code - change font and move baseline of the superscript
[attributedString addAttribute:NSFontAttributeName
                         value:[font fontWithSize:(font.pointSize / 2.0f)] 
                         range:superscriptRange];
[attributedString addAttribute:NSBaselineOffsetAttributeName 
                         value:[NSNumber numberWithFloat:(font.ascender / 2.0f)]
                         range:superscriptRange];
//end of the important code

[button setAttributedTitle:attributedString forState:UIControlStateNormal];