setShowsTouchWhenHighLighted

setShowsTouchWhenHighLighted

我创建了一个像这样的按钮:

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];


因此,我的头衔使问题显而易见。当我触摸并按住iPhone中的“创建的”按钮时,它仍然突出显示为蓝色。主要问题是插入的两个标签没有突出显示。如何禁用突出显示(请注意,我已经插入了 [meerKnop setShowsTouchWhenHighlighted:NO];,但这不起作用),或者如何使两个标签通过按钮突出显示?

最佳答案

“ setShowsTouchWhenHighlighted:”方法可防止按钮发光,即防止用户按下按钮时出现在按钮外部的光环。按钮被涂成蓝色的事实是UIButton的标准行为,据我所知,如果不重写批量绘制方法,就不能轻易更改它。

如果可以使标签也一样,可以将按钮变为蓝色,则可以使标签背景透明,如下所示:

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


或者像这样:

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

10-08 07:42