如果文章对您有用,麻烦顺手点一下文章的广告吧~

东东

ios选取图片的某一像素进行放大做文字背景
效果图:参考代码:UILabel *contentLabel = [[UILabel alloc]init]; ...
扫描右侧二维码阅读全文
11
2015/02

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