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];
已经,但这不起作用),或者如何让两个标签用按钮突出显示?
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 that I've inserted
already, but this doesn't work), or how can I let the two labels highlight with the button?
[meerKnop setShowsTouchWhenHighlighted:NO];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“setShowsTouchWhenHighlighted:”方法防止按钮发光,即防止当用户按下按钮时按钮外部出现光环。按钮颜色为蓝色的事实是标准的 UIButton 行为,据我所知,如果不大规模覆盖绘图方法,就无法轻松更改它。
如果您可以让按钮变成蓝色,如果您可以使标签做同样的事情,那么您可以使标签背景透明,如下所示:
或者可能像这样:
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:
or maybe like this: