2013-10-26 75 views
0

enter image description here的drawRect在IOS映像像下面图片

这是同步我的应用程序,我想是我想要显示的图像作为联系人图片和消息像文字下方透明的矩形,我想创建图像相同的矩形,他们已经表现出像地图,

目前我在做什么是这样的 -

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; 
} 
+0

那么什么是你的问题,只是如何让透明的黑色矩形? – Jing

+0

如果是这样,使用UIKit更容易作为您的最后一个问题。不需要使用Quartz。只需使用UILable并设置其背景色,如UIColor * color = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5]; – Jing

+0

我想要与第一张图像相同的矩形。怎么做 ? – krish

回答

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); 
} 
+0

仍然,实际上不需要深入石英。但在上一个问题中看到您的评论后添加石英代码 – Jing