需要在iPhone应用程序的收藏夹页面添加或删除菜单图标



我有20个按钮。需要使用scrollview动态地从UIView中添加和删除按钮。

,

 ![from this image  click star buttons to remove or add buttons.][1]

     https://i.stack.imgur.com/fnRxG.jpg

请使用属性tag。它是一个整数,你可以用它来标识应用程序中的视图对象。

@property(nonatomic) NSInteger tag
添加的示例代码:
UIButton *btnOk = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, 50, 50)];
[btnOk setTag:100];
//add target and set other properties here.
[self.view addSubview:btnOk];
btnOk = nil;

删除示例代码:

UIButton *btnOk =  [[self.view viewWithTag:100] isKindOfClass:[UIButton class]]?(UIButton *)[self.view viewWithTag:100]:nil;
[btnOk removeFromSuperview];

最新更新