Your example button is self.exampleButton...
-(UIButton*)_copie
{
NSData *arch = [NSKeyedArchiver archivedDataWithRootObject: self.exampleButton];
UIButton *nu = [NSKeyedUnarchiver unarchiveObjectWithData: arch];
[self.view addSubview:nu];
nu.frame = self.exampleButton.frame;
[nu addTarget:self
action:@selector(oneLinkClicked:)
forControlEvents:UIControlEventTouchUpInside];
return nu;
}
here‘s an example of making a number of the buttons, in a vertical column.
in the example the data comes from a Dictionary...
CGPoint zero = self.exampleButton.center;
CGFloat gap = self.exampleButton.bounds.size.height * 1.25;
NSInteger kount=0;
self.orderedLinks = [[NSMutableArray alloc] init];
for ( NSDictionary *link in self.arrayOfLinks )
{
NSLog( @"one title... %@", link[@"title"] );
NSLog( @"one url... %@", link[@"url"] );
UIButton *copy = [self _copie];
CGPoint newpos = zero;
newpos.y = newpos.y + ( kount * gap );
copy.center = newpos;
[copy setTitle:link[@"title"] forState:UIControlStateNormal];
copy.tag = kount;
[self.orderedLinks addObject:link[@"url"]];
kount++;
}
[self.exampleButton removeFromSuperview];
and when a button is clicked...
-(IBAction)oneLinkClicked:(UIButton *)sender
{
NSLog(@"this tag clicked ...... %ld", (long)sender.tag);
NSString *goUrl = self.orderedLinks[ sender.tag ];
NSLog(@"goUrl ...... %@", goUrl );
}
|