0

我正在尝试使用https://github.com/honcheng/RTLabel获取富文本标签,但我的直接目标是显示“Hello, world!”

我的代码是:

        UIImageView *noteImage = [[UIImageView alloc] initWithFrame:bounds];
        noteImage.image = image;
        [self.view addSubview:noteImage];
        CJSHCardView *noteView = [[CJSHCardView alloc] initWithImage:image];
        [noteView setFrame:CGRectMake(100 * i, 20, 100 * scale, 100 * scale)];
        noteView.transform = CGAffineTransformScale(noteView.transform, scale_x, scale_y);
        NSString *text = @"Hello, world!";
        RTLabel *label = [[RTLabel alloc] initWithFrame:CGRectMake(100 * i, 20, 100 * scale, 100 * scale)];
        [noteImage addSubview:label];
        [label setText:text];

我在倒数第二行尝试了 noteImage 和 noteView 。该矩形与原始图像具有相同的尺寸,可以正确显示。但是,我尝试过的所有方法似乎都不适合在 noteImage / noteView 顶部显示标签作为背景。

什么是让标签(最好是支持富文本的标签)显示在用作背景的图像顶部的合适方法?

4

1 回答 1

1

iOS 7 的 UILabel 支持属性字符串,因此除非您需要针对早期版本,否则我建议您只需在界面生成器中构建您的 UI 并根据需要在代码中设置属性文本。

于 2013-10-01T19:23:37.107 回答