开发者

setShowsTouchWhenHighLighted not working

I've created a button like this:

UIButton *meerKnop = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[[meerKnop layer] setCornerRadius:10.0f];
meerKnop.backgroundColor = [UIColor whiteColor];
meerKnop.frame = CGRectMake(11.0, (60.0 + (teller * 52.5)), 299.0, 50.0);

UILabel *locationLabel = [[UILabel alloc] initWithFrame:CGRectMake(17.5, 3.0, 128.0, 20.0)];
[locationLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]];
locationLabel.minimumFontSize = 12;
locationLabel.textColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.27 alpha:1.0];
locationLabel.lineBreakMode = UILineBreakModeTailTruncation;
[locationLabel setText:[[NSMutableString alloc] initWithFormat:@"%@", [incLocations objectAtIndex:teller]]];
[meerKnop addSubview:locationLabel];

UILabel *categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(17.5, 24.0, 256.0, 20.0)];
categoryLabel.lineBreakMode = UILineBreakModeTailTruncation;
[categoryLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]];
categoryLabel.minimumFontSize = 12;
categoryLabel.textColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.27 alpha:1.0];
[categoryLabel setText:[[NSMutableString alloc] initWithFormat:@"%@", [incInfos objectAtIndex:teller]]];
[meerKnop addSubview:categoryLabel];

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
swipe.direction = UISwipeGestureRecognizerDirectionRight;
[meerKnop addGestureRecognizer:swipe];
[swipe release];

int incId = (int)[incIds objectAtIndex:teller];
[meerKnop addTarget:self action:@selector(alertPressed:) forControlEvents:UIControlEventTouchUpInside];
meerKnop.tag = incId;
[[meerKnop layer] setMasksToBounds:YES];
[meerKnop setShowsTouchWhenHighlighted:NO];
[cell addSubview:meerKnop];

So, my title makes the question obvious. When I touch and hold the created button in the iPhone, it still highlights blue. The main problem is, the two labels inserted don't highlight. How do I disable the highlight (note tha开发者_开发百科t I've inserted [meerKnop setShowsTouchWhenHighlighted:NO]; already, but this doesn't work), or how can I let the two labels highlight with the button?


The "setShowsTouchWhenHighlighted:" method prevents the button from glowing, i.e. prevents the aura that appears around the outside of the button when a user presses it. The fact that the button is coloured blue is standard UIButton behaviour and it can't to my knowledge be easily changed without overriding the drawing method wholesale.

If you are okay with the button turning blue if you can make the labels do the same, then you can make the label backgrounds transparent like this:

locationLabel.backgroundColor = [UIColor clearColor];
categoryLabel.backgroundColor = [UIColor clearColor];

or maybe like this:

locationLabel.opaque = NO;
categoryLabel.opaque = NO;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜