【问题标题】:How do I put an RTLabel on an iOS image?如何在 iOS 图像上添加标签?
【发布时间】:2013-10-01 15:28:26
【问题描述】:

我正在尝试使用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 顶部显示标签作为背景。

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

【问题讨论】:

    标签: ios objective-c ipad label richtext


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-02
      • 2016-07-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多