【问题标题】:drag drop issue in buttons按钮中的拖放问题
【发布时间】:2014-10-24 10:38:12
【问题描述】:

我已经通过代码创建了几个按钮

    for(int i=0;i<2;i++)
{
            UIButton *btn_pin = [[UIButton alloc] initWithFrame:CGRectMake(100*i,100*i, 20, 20)];
            [btn_pin setBackgroundColor:[self colorFromHexString:@"5DBBAB"]];
            [btn_pin setTitle:[NSString stringWithFormat:@"%d",[arr_product count]+1] forState:UIControlStateNormal];
            [btn_pin.titleLabel setFont:[UIFont fontWithName:@"ProximaNova-Regular" size:10.0]];
            btn_pin.layer.cornerRadius = 10.0;
            btn_pin.layer.masksToBounds = YES;
            btn_pin.layer.borderColor = [UIColor whiteColor].CGColor;
            btn_pin.layer.borderWidth = 1.0;
            btn_pin.userInteractionEnabled = TRUE;
            btn_pin.titleEdgeInsets = UIEdgeInsetsMake(2, 0, 0, 0);
            [btn_pin.layer setBorderColor:[UIColor whiteColor].CGColor];
            [btn_pin addTarget:self action:@selector(imageMoved:withEvent:) forControlEvents:UIControlEventTouchDown];
            [btn_pin addTarget:self action:@selector(imageMoved:withEvent:) forControlEvents:UIControlEventTouchDragInside];

            [img_main addSubview:btn_pin];
            [tbl_product reloadData];
}

现在我想通过拖动来移动这些按钮,我已经创建了一个拖放,但是我如何获得这个按钮的引用。

【问题讨论】:

    标签: ios drag-and-drop drag


    【解决方案1】:

    在你的循环中:

    btn_pin.tag = i;
    

    在 imageMoved 中:

    UIButton *btn_pin = (UIButton *)sender;
    int refIndex = btn_pin.tag;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-09
      • 2018-11-21
      • 2020-10-08
      • 1970-01-01
      相关资源
      最近更新 更多