xcode,ios开发,通过tag调用button
-(void)viewDidLoad{[superviewDidLoad];//Doanyadditionalsetupafterloadingtheview,typic...
- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. for(int i=2000;i<2015;i++){ self.y +=30; UIButton *btn1=[UIButton buttonWithType:UIButtonTypeRoundedRect]; btn1.backgroundColor=[UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0]; [btn1 setTitle:@"Button" forState:UIControlStateNormal]; btn1.frame=CGRectMake(((arc4random()%260)+10), self.y, 50, 20); btn1.tag =i; [self.view addSubview:btn1]; NSLog(@"tag=%ld",(long)btn1.tag); }}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}- (IBAction)createBtn:(id)sender { for(int c=2000;c<2015;c++){ UIButton *btn1=[UIButton alloc]; btn1.tag=c; btn1.backgroundColor=[UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0]; }
}
我在viewDidload里面生成了一堆按钮,横坐标不同,背景色不同,tag值不同,现在我要添加一个Create按钮,希望每次点击,都会改变这堆按钮的横坐标值和背景色,请问怎么操作? 展开
}
我在viewDidload里面生成了一堆按钮,横坐标不同,背景色不同,tag值不同,现在我要添加一个Create按钮,希望每次点击,都会改变这堆按钮的横坐标值和背景色,请问怎么操作? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |