Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
971 views
in Technique[技术] by (71.8m points)

iphone - UIButton color issues

How can I change the color of the text on my UIButton. Here is my current code:

    UIButton *b1 = [[UIButton alloc] init];
    b1.frame = CGRectMake(280,395,30,30);
    [[b1 layer] setCornerRadius:8.0f];
    [[b1 layer] setMasksToBounds:YES];
    [[b1 layer] setBorderWidth:1.0f];
    [[b1 layer] setBackgroundColor:[botCol CGColor]];
    b1.titleLabel.font = [UIFont boldSystemFontOfSize:24];
    [b1 setTitleColor:[UIColor redColor] forState:UIControlEventAllEvents];
    [b1 addTarget:self action:@selector(NextButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [b1 setTitle:@">" forState:UIControlStateNormal];
    [self.view addSubview:b1];

Here is what it looks like (ignore the background color and stuff):

enter image description here

Now, how can I get the arrow to be red? As you see above, I already have the following:

[b1 setTitleColor:[UIColor redColor] forState:UIControlEventAllEvents];

but it isn't working.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try setting the individual events, such as:

[b1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...