-1

我想在 CGContext 中绘制文本。当我从字符串中写入文本时,我会绘制文本。但我想提示用户这个文本。我能怎么做?

4

1 回答 1

0

你可以使用 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]

于 2012-10-06T15:33:06.023 回答