简体   繁体   中英

How do I drag and drop a label to autocomplete textfield?

I want to drag and drop a label or something that will autocomplete the UITextfield. For example if I have an empty textfield and I drag a label with text "hello world" on top of the textfield, the textfield will have "hello world" as its text. Does anyone know how I can do this? Is a UILabel the best choice to use? or perhaps a UIButton could work?

You better read the tutorial first about IOS development. follow the tutorial

in this site http://www.appcoda.com/ios-programming-course/

For your question study the following link first then arise the questions

http://www.appcoda.com/hello-world-build-your-first-iphone-app/
http://www.appcoda.com/ios-programming-basic-how-does-the-hello-world-app-work/

Try this

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
   //get position
   // get label on that position
   [label removeFromSuperView];
   newLabel = [[UILabel alloc] init]; 
   [self.view addSubView:newLabel]; //positioned at label
}

touchesMoved {
   //getPosition
   newLabel.position = position;
}

touchesEnded {
   //getPosition.
   self.view.subviews; // loop and find which view has the position.

   UILabel *finalLabel = [[UILabel alloc] init];
   finalLabel.center = newLabel.center;

   [newLabel removeFromSuperView];

   [viewToBeDroppedOn addSubview:finalLabel];
}

Also Check this tutorial Drag & Drop

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM