UIButton title disappears on touch
Posted
by
psychotik
on Stack Overflow
See other posts from Stack Overflow
or by psychotik
Published on 2010-12-29T19:48:28Z
Indexed on
2010/12/29
19:54 UTC
Read the original article
Hit count: 194
I want a touchable UILabel
, but since that's not possible I decided to create a UIButton
of type UIButtonTypeCustom
. It looks how I want it to look, but when I touch it, the title disappears. I tried setting the title for state UIControlStateHighlighted
but that didn't help. I know I'm doing something really silly here, but can't figure it out.
I tried a few things (commented in the code below) which didn't seem to help. Here's how I'm configuring the button:
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, width, height);
button.clearsContextBeforeDrawing = YES;
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
button.enabled = YES;
button.hidden = NO;
button.highlighted = NO;
button.opaque = YES;
button.selected = NO;
button.userInteractionEnabled = YES;
button.showsTouchWhenHighlighted = NO;
[button setTitle:@"Hello World" forState:UIControlStateNormal];
button.titleLabel.font = [UIFont boldSystemFontOfSize:16];
button.titleLabel.textColor = [UIColor blackColor];
// Things I tried that didn't help
//[button setBackgroundColor:[UIColor clearColor]];
//button.titleLabel.text = @"Hello World";
//[button setTitle:@"Hello World" forState:UIControlStateHighlighted];
Any ideas?
© Stack Overflow or respective owner