Trevor McKendrick
Trevor McKendrick

Reputation: 595

UIButton Title Doesn't Appear unless Clicked

I don't know how to describe the problem other than the title of the question: I have a button with title that appears when it's clicked, but not in its normal state. I've looked around everywhere to no avail.

If you need to see specific code or want other details (as I'm sure you will) just let me know.

EDIT: The button is created in a nib, but here is the code that sets the title and also deals with a subview of the button.

[chapterButton setTitle:[NSString stringWithFormat:@"%@: %d",newBookName,newChapter] forState:UIControlStateNormal];

UIImageView *triunghiView = (UIImageView *) [chapterButton viewWithTag:kTagTriangleView];
if(!triunghiView)
{
    triunghiView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"triunghi.png"]] autorelease];
    [triunghiView setContentMode:UIViewContentModeCenter];
    [triunghiView setTag:kTagTriangleView];
    [triunghiView sizeToFit];
    [chapterButton addSubview:triunghiView];

}

[triunghiView setCenter:CGPointMake(chapterButton.titleLabel.frame.origin.x + chapterButton.titleLabel.frame.size.width + triunghiView.frame.size.width + 5, chapterButton.frame.size.height/2)];

Upvotes: 0

Views: 229

Answers (2)

borrrden
borrrden

Reputation: 33421

I had this problem recently, you have to also set the title color of your button, or else it will turn white and appear invisible (in the default setup of round rect button).

[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

However, it could also likely be Kjuly's answer! Without code it is hard to tell.

Upvotes: 3

Kjuly
Kjuly

Reputation: 35131

No code, well, guess you might set a wrong state for your title.

[yourButton setTitle:@"Title" forState:UIControlStateNormal];

Upvotes: 0

Related Questions