我有一个应用程序,我正在用手指做签名,它工作正常,它画线,但我想将这些线绘制的签名保存为 ImageView 中的图像以显示屏幕,但它没有显示我正在使用以下代码。
-(void)onSignButtonClick
{
signatureView=[[UIView alloc] initWithFrame:CGRectMake(100,100,800,500)];
signatureView.backgroundColor=[UIColor blackColor];
[self.view addSubview:signatureView];
UIButton*OkButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[OkButton setFrame:CGRectMake(100,420,200,40)];
[OkButton setTitle:@"OK" forState:UIControlStateNormal];
[OkButton addTarget:self action:@selector(onOKButtonClick) forControlEvents:UIControlEventTouchUpInside];
[signatureView addSubview:OkButton];
drawScreen=[[MyLineDrawingView alloc]initWithFrame:CGRectMake(10,10,700,400)];
[signatureView addSubview:drawScreen];
[drawScreen release];
}
- (UIImage *)captureView {
//hide controls if needed
CGRect rect = [signatureView bounds];//use your signature view's Rect means Frame;
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
-(void)onOKButtonClick{
signatureView.hidden=YES;
[self captureView];
logoImageView.image=signatureImage;
}