我遇到了拖放UILabel的问题。
如何拖拽标签(Move This)并拖放到任何一个UIToolBar项目上(例如,1、2或3...)该按钮标题应更改为标签文本。
Check image for this question
发布于 2013-05-28 21:22:37
使用自定义按钮作为标签,然后使用以下代码:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self action:@selector(btnTouch:withEvent:) forControlEvents:UIControlEventTouchDown];
button.tag = -1;
button.titleLabel.text = @"Move this";
[button addTarget:self action:@selector(btnTouch:withEvent:) forControlEvents:UIControlEventTouchDragInside];
[self.view addSubview:button];然后,您可以通过响应UIControlEventTouchDragInside事件将臀部移动到您想要的任何位置,例如:
- (IBAction) btnTouch:(id) sender withEvent:(UIEvent *) event
{
CGPoint point = [[[event allTouches] anyObject] locationInView:self.view];
UIControl *control = sender;
control.center = point;
//Here use this to check when intersects and check if the frame of the item you are moving intersects with the frame from on of your subviews
for (UIView *anotherBtn in self.view.subviews) {
if (CGRectIntersectsRect(control.frame, anotherBtn.frame)) {
// Do something
[anotherBtn setTitle:control.titleLabel.text];
}
}
}希望能对你有所帮助。
发布于 2013-05-28 21:16:59
UIBarButtonItem有它自己的标题,你不能在上面拖拽标签
https://stackoverflow.com/questions/16792771
复制相似问题