2013-10-26 38 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