我正在开发一款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];
一切都很好,除了一点点,但仍然令人讨厌的细节:
如您所见,所选按钮的左上角有一些蓝色的“方框”或阴影。正常状态下的按钮没有这样的东西。它可以来自什么,以及如何删除它?
答案 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)