次のようなボタンをプログラムで生成しました。
- (void)viewDidLoad
{
[super viewDidLoad];
int y = 127;
for (int i=0; i<=6; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchDown];
//[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(26, y, 268, 41);
[button setTitle:[NSString stringWithFormat:@"Button-%i", i] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"cys_button.png"] forState:UIControlStateNormal];
[button.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeueLTPro-Cn" size:21]];
[button setTitleColor:[UIColor colorWithRed:60/255.0 green:60/255.0 blue:60/255.0 alpha:1] forState:UIControlStateNormal];
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
button.contentEdgeInsets = UIEdgeInsetsMake(8, 15, 0, 0);
[scrollViewContent addSubview:button];
y=y+43;
}
}
クリック後にテキストを表示するメソッド:
-(void)aMethod:(id)sender{
UIButton *button = sender;
int y = 127;
int i = 6;
for (int x=0; x<=i; x++) {
NSString *frameString = [NSString stringWithFormat:@"{{26, %i}, {268, 41}}", y];
if ([NSStringFromCGRect(button.frame) isEqualToString:frameString]) {
NSLog(@"button %i clicked..", x);
}
y= y+43;
}
}
ボタンをクリックして次のビューに転送する方法は?