【发布时间】:2013-10-26 12:55:32
【问题描述】:
这是同步我的应用程序,我想要的是将图像显示为联系人图片和消息,如下面的透明矩形与文本,我想创建与图像相同的矩形,它们显示为地图,
目前我正在做的是这个 -
我只是想像第一张图片一样更改图像,我的消息应该出现在这个矩形框中,下面的小图像应该出现在地图图像中。
这是我当前的代码:
-(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;
}
【问题讨论】:
-
那你有什么问题,如何获得透明的黑色矩形?
-
如果是这样,使用 UIKit 作为您的最后一个问题更容易。无需使用石英。只需使用 UILable 并设置其背景颜色,例如 UIColor *color = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5];
-
我想要与第一张图片相同的矩形。该怎么做?
标签: ios uiimageview drawrect quartz-2d