0

在此处输入图像描述

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

目前我正在做的是这个 -

在此处输入图像描述]![在此处输入图像描述

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

这是我当前的代码:

-(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;
}
4

1 回答 1

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

---------------------石英版---------

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

下面是用圆角半径绘制矩形的代码

- (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);
}
于 2013-10-28T02:07:03.653 回答