如何添加带有下标的表视图节标题? [英] How to add table view section header with subscripts?

查看:128
本文介绍了如何添加带有下标的表视图节标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有一个表视图,我已经管理了故事板(我已经添加了部分:行:单元格等所有通过故事板),我所做的编程方式的唯一的变化是添加一个 UIButton 作为其中一个节标题:

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;
}



我目前的困境是我必须添加一个包含下标的节头, ie:H2O

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

我无法直接在故事板检查器中添加下标,有人可以告诉我这是怎么做的?

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.

推荐答案

一个简单的解决方案是使用Unicode下标范围,U + 2080至U + 2089。例如:2 H 2 + O 2 - > 2 H 2 O。

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

您可以使用Unicode Hex输入键盘布局输入其中一个字符, (例如保持选项,并为o键入2080)。

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 "₀").

给定一个数字,您可以将其格式化为字符串, p>

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

这篇关于如何添加带有下标的表视图节标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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