2012-11-28 57 views
-3

我一直在研究这个问题,但我发现的答案不起作用。如何将textview添加到图像视图?

[myImageView addSubview:myTextView]; 

我想要的文字变成图像的一部分,所以如果我救myImageView至相机胶卷,文本将被包括在内。 我做错了什么或有另一种方式来做到这一点?

+1

检查。 http://stackoverflow.com/a/13522413/1730272。这是你正在寻找的 – iDev

回答

1

假设你已经有了一个UIImage IMG,然后用下面的代码中添加文本

-(void)drawText:(NSString *)text onImage:(UIImage *)img 
{ 
    UIFont *font = yourTextViewFont; 
    UIGraphicsBeginImageContext(img.size); 
    [img drawAtPoint:CGPointZero]; 
    CGContextSetRGBFillColor(UIGraphicsGetCurrentContext(), 1.0, 1.0, 1.0, 1); 
    [text drawAtPoint: CGPointMake(20, 20) withFont: font]; 

    UIImage *ret = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    return ret; 
}