Tôi đang tạo một ứng dụng iPhone mà tôi có nút tùy chỉnh. tôi đã đặt tiêu đề cho các nút bằng cách tạo một Nhãn và thêm nó làm phần phụ. bây giờ khi nút được tô sáng, tôi muốn thay đổi màu chữ của nhãn.Cách đặt màu văn bản nhãn của nhãn cho trạng thái UIControlStateHighlighted
đây là mã của tôi,
UIButton *button1= [UIButton buttonWithType:UIButtonTypeCustom];
[button1 setFrame:CGRectMake(68,162, 635, 101)];
[button1 setImage:[UIImage imageNamed:@"startwithouttext.png"] forState:UIControlStateNormal];
[button1 setImage:[UIImage imageNamed:@"startactivewithouttext.png"] forState:UIControlStateHighlighted];
UILabel *buttonLabel = [[UILabel alloc] initWithFrame:CGRectMake(button1.bounds.origin.x+50, button1.bounds.origin.y+20, button1.bounds.size.width-100, button1.bounds.size.height-40)];
[buttonLabel setFont:[UIFont fontWithName:@"Helvetica" size:28]];
buttonLabel.backgroundColor=[UIColor clearColor];
buttonLabel.textColor=[UIColor colorWithRed:83.0/255.0 green:83.0/255.0 blue:83.0/255.0 alpha:1.0];
buttonLabel.highlightedTextColor=[UIColor whiteColor];
buttonLabel.text = @"Long text string";
[button1 addSubview:buttonLabel];
[button1 bringSubviewToFront:buttonLabel];
[button1 setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[button1 setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[button1 addTarget:self action:@selector(button1clicked:) forControlEvents:
[mainView button1];
bất kỳ cơ thể có thể giúp tôi thay đổi màu sắc văn bản khi nút được nhấn mạnh?
được button1clicked gọi là? – Maulik
yes button1clicked được gọi là – krishan
tôi có thể thay đổi màu văn bản khi phương thức button1clicked được gọi, nhưng điều tôi muốn là thay đổi màu văn bản khi nút được highlihted – krishan