[英]How do I put an RTLabel on an iOS image?
I am trying to use https://github.com/honcheng/RTLabel to get a rich text label, but my immediate goal is to display "Hello, world!" 我正在尝试使用https://github.com/honcheng/RTLabel获取富文本标签,但我的近期目标是显示“世界你好!”
My code is: 我的代码是:
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];
I tried both noteImage and noteView in the second-to-last line. 我在倒数第二行尝试了noteImage和noteView。 The rectangle has the same dimensions as the original image, which is displaying correctly.
该矩形与正确显示的原始图像具有相同的尺寸。 However, none of the approaches I've tried seem apt to display a label on top of the noteImage / noteView as backgrounds.
但是,我尝试过的所有方法似乎都不适合在noteImage / noteView顶部显示标签作为背景。
What is an appropriate way to get a label (preferably one that supports rich text) to display on top of an image meant to serve as background for it? 使标签(最好是支持富文本的标签)显示在打算用作背景的图像上的合适方法是什么?
iOS 7的UILabel支持属性字符串,因此,除非您需要定位较早的版本,否则建议您仅在界面生成器中构建UI并根据代码中的需要设置属性文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.