iOS应用程序中自定义UIButton旁边显示“蓝框”

时间:2013-09-20 18:00:11

标签: iphone ios objective-c uibutton

我正在开发一款iPhone应用程序,它可以作为打开和关闭灯泡的遥控器,我正在使用UIButton来执行此操作:

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

一切都很好,除了一点点,但仍然令人讨厌的细节:

buttons

如您所见,所选按钮的左上角有一些蓝色的“方框”或阴影。正常状态下的按钮没有这样的东西。它可以来自什么,以及如何删除它?

3 个答案:

答案 0 :(得分:16)

我认为是因为您创建了UIButtonTypeRoundedRect而不是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];

答案 1 :(得分:5)

以编程方式[UIButton buttonWithType:UIButtonTypeCustom];

尝试此操作

答案 2 :(得分:4)

默认情况下,按钮类型为System,将按钮的类型更改为Custom

要修复的代码:

[UIButton buttonWithType:UIButtonTypeCustom];

要修复的故事板:

请参阅屏幕截图以修复stroryboard。

enter image description here