Ios 如何在CGContext中绘制提示用户的文本

Ios 如何在CGContext中绘制提示用户的文本,ios,text,draw,cgcontext,Ios,Text,Draw,Cgcontext,我想在CGContext中绘制文本。当我从字符串中写入文本时,我会绘制文本。但是我想提示用户这个文本。如何操作?您可以使用UIAlertView: UIAlertView* alert = [[UIAlertView alloc] init]; alert.message = @"Enter new string"; alert.alertViewStyle = UIAlertViewStylePlainTextInput; UITextField* textField = [alert tex

我想在CGContext中绘制文本。当我从字符串中写入文本时,我会绘制文本。但是我想提示用户这个文本。如何操作?

您可以使用UIAlertView:

UIAlertView* alert = [[UIAlertView alloc] init];
alert.message = @"Enter new string";
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField* textField = [alert textFieldAtIndex:0];
textField.placeholder = @"text";

[alert addButtonWithTitle:@"Cancel"];
[alert addButtonWithTitle:@"OK"];
alert.cancelButtonIndex = 0;
alert.delegate = self;
[alert show];
处理“确定”按钮按下:

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.cancelButtonIndex != buttonIndex) {
        NSString* text = [alertView textFieldAtIndex:0].text;
        [self.myView setString:text];


    }
}

自定义视图的方法
setString:
应设置其NSString ivar,并调用
[self-setNeedsDisplay]
或-如果您知道字符串的绘制帧-最好调用
[self-setNeedsDisplayInRect:stringFrame]

谢谢您的帮助。这是有用的。