How to create a UITextField on SpriteKit

后端 未结 2 1162
清酒与你
清酒与你 2020-12-31 23:12

I want to implement a Textfield to input your name on my SpriteKit Game, so I have something like this:

SKLabelNode* gameTitle = [SKLabelNode labelNodeWithFo         


        
2条回答
  •  独厮守ぢ
    2020-12-31 23:31

    You can add objects that inherits UIView's inside the didMoveToView:(SKView *)view function

    Just add that function to your SKScene and move your UITextField inside:

    -(void)didMoveToView:(SKView *)view {
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(self.size.width/2, self.size.height/2+20, 200, 40)];
        textField.center = self.view.center;
        textField.borderStyle = UITextBorderStyleRoundedRect;
        textField.textColor = [UIColor blackColor];
        textField.font = [UIFont systemFontOfSize:17.0];
        textField.placeholder = @"Enter your name here";
        textField.backgroundColor = [UIColor whiteColor];
        textField.autocorrectionType = UITextAutocorrectionTypeYes;
        textField.keyboardType = UIKeyboardTypeDefault;
        textField.clearButtonMode = UITextFieldViewModeWhileEditing;
        textField.delegate = self.delegate;
        [self.view addSubview:textField];
    }
    

提交回复
热议问题