[英]Custom multiline UILabel with black background behind text
I need to create custom multiline UILabel with black background behind text, with some pading of 2 pixel from left, right, top and bottom. 我需要创建自定义多行UILabel,并在文本后面添加黑色背景,并从左,右,顶部和底部填充2像素。 Padding must be same for all side, let say if padding between [Songs.. and black border = 2 then I need 2pixel padding between "Perfect" and right border, same after "mp3"
每一边的填充都必须相同,假设[Songs ..和黑色边框= 2之间的填充,那么我需要在“ Perfect”和右侧边框之间填充2pixel,在“ mp3”之后相同
I tried this: 我尝试了这个:
[string addAttribute:NSBackgroundColorAttributeName
value:[UIColor blackColor]
range:NSMakeRange(0, string.length)];
but its not giving me extra padding. 但它没有给我额外的填充。
Could you guys suggest me any library or some hint will also be helpful 你们能建议我任何图书馆还是一些提示也会有所帮助
I would use a UITextView
rather than a UILabel
. 我将使用
UITextView
而不是UILabel
。 Do something like the following: 执行以下操作:
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(10, y, self.view.frame.size.width - 20, 40)];
textView.textAlignment = NSTextAlignmentJustified;
textView.scrollEnabled = NO;
textView.backgroundColor = [UIColor blackColor];
textView.userInteractionEnabled = NO;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.