Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
579 views
in Technique[技术] by (71.8m points)

ios - How to add table view section header with subscripts?

In my app, I have a table view that I have managed so far with storyboards (I have added sections:rows:cells, etc.. all via storyboards), the only change I have made programmatically was to add a UIButton as one of the sections headers by implementing:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 2) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 64)];

        UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];

        [button1 setTitle:@"Hydro Volume" forState:UIControlStateNormal];

        button1.frame = CGRectMake(62.5, 5, 205, 44);

        [view addSubview:button1];

        [button1 addTarget: self
                    action: @selector(buttonClicked:)
          forControlEvents: UIControlEventTouchDown];

        return view;
    }

    return nil;
}

My current dilemma is that I have to add a section header that contains subscripts, i.e.: H2O image of a checmical formula with subscripts

I am unable to just add the subscript directly in the storyboard inspector, can someone tell me what is the way to do this?

I reviewed this question, but it's not quite what I am looking for as I need to be able to add it to my section header.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

One simple solution is to use the Unicode subscript range, U+2080 through U+2089. Example: 2 H? + O? -> 2 H?O.

You can type one of these characters by using the Unicode Hex Input keyboard layout, holding Option, and typing the hex digits (e.g. hold option and type “2080” for “?”).

Given a single digit, you can format it into a string as a subscript like this:

static const unichar kSubscriptZero = 0x2080;
int numberOfHydrogens = 2;
NSString *water = [NSString stringWithFormat:@"H%CO",
    kSubscriptZero + numberOfHydrogens];

http://www.unicode.org/charts/PDF/U2070.pdf


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...