效果图:
参考代码:
UILabel *contentLabel = [[UILabel alloc]init];
contentLabel.textColor = [UIColor whiteColor];
contentLabel.backgroundColor = [UIColor clearColor];
//contentLabel.textAlignment = NSTextAlignmentCenter;//设置内容对齐
contentLabel.font = [UIFont boldSystemFontOfSize:13.0];
contentLabel.text = @"123456789";
CGSize size = [contentLabel.text sizeWithFont:contentLabel.font constrainedToSize:CGSizeMake(80, 100) lineBreakMode:NSLineBreakByWordWrapping];
UIImage* image = [UIImage imageNamed:@"Point.png"];
//选取图片的某一像素进行放大做文字背景
image = [image stretchableImageWithLeftCapWidth:20 topCapHeight:15];
contentLabel.frame = CGRectMake(15, 4, size.width, size.height);
UIImageView* updateImage = [[UIImageView alloc]initWithFrame:CGRectMake(320-30-size.width, 150, 30+size.width ,10+size.height )];
updateImage.image = image;
[updateImage addSubview:contentLabel];
[self.view addSubview:updateImage];
附加上那个图片资源:point.png
版权属于:东哥笔记 - DongGe.org
本文链接:http://dongge.org/blog/25.html
本文采用知识共享署名4.0 国际许可协议进行许可。转载或大段使用必须添加本文链接,否则您将构成侵权!