0

for ループを使用して 3 つのカスタム ボタンを作成しました。しかし、ボタンを選択してもテキストの色が変わりません。どうすればよいですか? 他に何を追加する必要がありますか?

これが私のコードです

buttonText = [[NSArray alloc]initWithObjects: @"Slambook",@"Initiated",@"Collaborated",nil];    
NSInteger numControllers = [viewControllerArray count];

for (int i = 0; i<numControllers; i++) {

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(X_BUFFER+i*(self.view.frame.size.width-2*X_BUFFER)/numControllers-X_OFFSET, Y_BUFFER, (self.view.frame.size.width-2*X_BUFFER)/numControllers, HEIGHT);
    [button setTitleColor:[UIColor colorWithRed:137.0/255.0 green:110.0/255.0 blue:255.0/255.0 alpha:1] forState:UIControlStateHighlighted];
    [button setTitleColor:[UIColor colorWithRed:137.0/255.0 green:110.0/255.0 blue:255.0/255.0 alpha:1] forState:UIControlStateSelected];
    [button setTitle:[buttonText objectAtIndex:i] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(tapButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [navigationView addSubview:button];
}
4

2 に答える 2