“蓝框"显示在iOS应用中的自定义UIButton旁边 [英] "Blue box" showing up next to custom UIButton in iOS app

查看:71
本文介绍了“蓝框"显示在iOS应用中的自定义UIButton旁边的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iPhone应用程序,该应用程序可作为打开和关闭灯泡的遥控器,并且我正在使用UIButtons来做到这一点:

I'm developing an iPhone app that acts as a remote for switching lightbulbs on and off, and I'm using UIButtons to do this:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];

[button setBackgroundImage:bulb_on forState:UIControlStateSelected];
[button setBackgroundImage:bulb_off forState:UIControlStateNormal];

button.frame = CGRectMake(SPACING_LEFT + (BUTTON_SPACING * buttonNum) % (NUMBER_OF_HORIZONTAL_BUTTONS * BUTTON_SPACING), SPACING_TOP + y_padding, BUTTON_SIZE_X, BUTTON_SIZE_Y);

[self.scrollView addSubview:button];

一切正常,除了一点点,但仍然令人讨厌的细节:

Everything works fine, except a little, but still annoying detail:

如您所见,所选按钮的左上角有某种蓝色的盒子"或阴影.处于正常状态的按钮没有这种东西.这可以从哪里来,以及如何将其删除?

As you can see, there is some kind of blue "box" or shadow in the top left corner of the selected button. The button in normal state has no such thing. What can this come from, and how to remove it?

推荐答案

我认为这是因为您创建了UIButtonTypeRoundedRect而不是buttonWithType:UIButtonTypeCustom

I think it s because you created a UIButtonTypeRoundedRect not a buttonWithType:UIButtonTypeCustom

这样做:

UIButton *button = [[UIButton alloc]initWithFrame: CGRectMake(SPACING_LEFT + (BUTTON_SPACING * buttonNum) % (NUMBER_OF_HORIZONTAL_BUTTONS * BUTTON_SPACING), SPACING_TOP + y_padding, BUTTON_SIZE_X, BUTTON_SIZE_Y)];
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];

[button setBackgroundImage:bulb_on forState:UIControlStateSelected];
[button setBackgroundImage:bulb_off forState:UIControlStateNormal];

[self.scrollView addSubview:button];

这篇关于“蓝框"显示在iOS应用中的自定义UIButton旁边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆