首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在iphone的UIToolbarItem上拖放标签

如何在iphone的UIToolbarItem上拖放标签
EN

Stack Overflow用户
提问于 2013-05-28 21:00:06
回答 2查看 583关注 0票数 1

我遇到了拖放UILabel的问题。

如何拖拽标签(Move This)并拖放到任何一个UIToolBar项目上(例如,1、2或3...)该按钮标题应更改为标签文本。

Check image for this question

EN

回答 2

Stack Overflow用户

发布于 2013-05-28 21:22:37

使用自定义按钮作为标签,然后使用以下代码:

代码语言:javascript
复制
     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事件将臀部移动到您想要的任何位置,例如:

代码语言:javascript
复制
- (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];
        }
    }
}

希望能对你有所帮助。

票数 1
EN

Stack Overflow用户

发布于 2013-05-28 21:16:59

UIBarButtonItem有它自己的标题,你不能在上面拖拽标签

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16792771

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档