ios选取图片的某一像素进行放大做文字背景

效果图:

屏幕快照 2015-02-11 下午2.52.20.png

参考代码:

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

Point@2x.png



Last modification:January 1st, 1970 at 08:00 am
如果看了这个文章可以让你少加会班,可以请我喝杯可乐
已打赏名单
微信公众号

Leave a Comment