在图像中的图像上绘制如下图像

时间:2013-10-26 12:55:33

标签: ios uiimageview drawrect quartz-2d

enter image description here

这是同步我的应用程序,我想要的是我想将图像显示为联系人图片和消息如下面的透明矩形与文本,我想创建相同的矩形与图像,他们已经显示像地图,< / p>

目前我在做的是这个 -

enter image description here]![enter image description here

我只想像第一张图片一样更改图像,我的消息应该放在这个矩形框中,而下面的小图像就像地图图像一样。

这是我目前的代码:

-(UIImage *) drawText:(NSString*) text inImage:(UIImage*)image :(UIImage *)contact_picture
{
    UILabel *lblText=[[UILabel alloc]init];


    lblText.text=[NSString stringWithFormat:@"%@",text];
    lblText.font = [UIFont fontWithName:@"Helvetica-Bold" size:30.0f];



    UIFont *font =lblText.font;;
    if ([UIScreen instancesRespondToSelector:@selector(scale)]) {
        UIGraphicsBeginImageContextWithOptions(CGSizeMake(320.0, 480.0), NO, 0.0f);
    } else {
        UIGraphicsBeginImageContext(CGSizeMake(320.0, 480.0));
    }

    CGContextRef context = UIGraphicsGetCurrentContext();
    [image drawInRect:CGRectMake(0,0,320.0,480.0)];
    [contact_picture drawInRect:CGRectMake(230,295,90,90)];

    CGRect rect = CGRectMake(20,120,320, 480);//Set Frame as per your Requirement
    CGContextSetRGBFillColor(context, 255, 255, 255, 1);



    [text drawInRect:CGRectIntegral(rect) withFont:font];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return newImage;
}

1 个答案:

答案 0 :(得分:0)

如果你的意思是显示“Jennifier签入....”的矩形,你可以使用UIView。

UIView *myRectangle = [[UIView alloc] initWithFrame:rectangleFrame];
[myRectangle setBackgroundColor:transparantColor];
myRectangle.layer.cornerRadius = 3.0;
[myRectangle.layer setMasksToBounds:YES];

[yourSuperView addSubview:myRectangle];

//add your text view and image to myRectangle

--------------------- Quartz version ---------------------

绘制一个角半径的矩形,并用透明色填充它。

下面是绘制角半径

的矩形的代码
- (void)rectangleInPath:(CGMutablePathRef)path WithWidth:(CGFloat)width Height:(CGFloat)height Radius:(CGFloat)radius Offset:(CGFloat)offset{

    CGPathMoveToPoint(path, NULL, offset, offset+radius);
    CGPathAddArcToPoint(path, NULL, offset, offset, offset+radius, offset, radius);
    CGPathAddLineToPoint(path, NULL, width-radius-offset, offset);
    CGPathAddArcToPoint(path, NULL, width-offset, offset, width-offset, radius+offset, radius);
    CGPathAddLineToPoint(path, NULL, width-offset, height-radius-offset);
    CGPathAddArcToPoint(path, NULL, width-offset, height-offset, width-radius-offset, height-offset, radius);
    CGPathAddLineToPoint(path, NULL, radius+offset, height-offset);
    CGPathAddArcToPoint(path, NULL, offset, height-offset, offset, height-radius-offset, radius);
    CGPathAddLineToPoint(path, NULL, offset, offset+radius);
}