1.动态添加按钮
for (int i = 0; i<self.arrayPin.count; i++) {
NSString *xnum = [[self.arrayPin objectAtIndex:i] objectForKey:@"x"];
NSString *ynum = [[self.arrayPin objectAtIndex:i] objectForKey:@"y"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *buttonimage = [UIImage imageNamed:@"needle1"];
[button setFrame:CGRectMake([xnum intValue]-buttonimage.size.width, [ynum intValue]- buttonimage.size.height, buttonimage.size.width, buttonimage.size.height)];
[button setImage:buttonimage forState:UIControlStateNormal];
[button setTag: i+1];
[button addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
[buttonArray addObject:button];//按钮加到数组里
}
2.遍历动态添加的按钮
[buttonArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){
UIButton *button =obj;
[button setHidden:YES];
}];