16

我正在开发一个 iPhone 应用程序,它充当开关灯泡的遥控器,我正在使用 UIButtons 来执行此操作:

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

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

纽扣

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

4

3 回答 3

18

我认为这是因为你创建了一个UIButtonTypeRoundedRectnot abuttonWithType: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];
于 2013-09-20T18:02:40.457 回答
7

默认按钮类型是System,将按钮的类型更改为Custom


要修复的代码:

[UIButton buttonWithType:UIButtonTypeCustom];


要修复的情节提要:

请参阅屏幕截图以在故事板中修复。

在此处输入图像描述

于 2015-08-06T14:51:20.557 回答
5

以编程方式尝试此操作[UIButton buttonWithType:UIButtonTypeCustom];

于 2013-09-20T18:02:11.443 回答