setShowsTouchWhenHighLighted 不起作用

发布于 2024-11-15 21:39:08 字数 1986 浏览 2 评论 0原文

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

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
[meerKnop setShowsTouchWhenHighlighted:NO];
already, but this doesn't work), or how can I let the two labels highlight with the button?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫性小仙女 2024-11-22 21:39:08

“setShowsTouchWhenHighlighted:”方法防止按钮发光,即防止当用户按下按钮时按钮外部出现光环。按钮颜色为蓝色的事实是标准的 UIButton 行为,据我所知,如果不大规模覆盖绘图方法,就无法轻松更改它。

如果您可以让按钮变成蓝色,如果您可以使标签做同样的事情,那么您可以使标签背景透明,如下所示:

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

或者可能像这样:

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

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文