我通过代码
创建了几个按钮 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];
}
现在我想通过拖动来移动这些按钮,我已经创建了拖放,但我如何获得此按钮的引用。
答案 0 :(得分:0)
在你的循环中:
btn_pin.tag = i;
并在imageMoved中:
UIButton *btn_pin = (UIButton *)sender;
int refIndex = btn_pin.tag;