iphone - "Blue box"显示在 iOS 应用程序中的自定义 UIButton 旁边

标签 iphone ios objective-c uibutton

我正在开发一个 iPhone 应用程序,它可以充当开关灯泡的 Remote ,我正在使用 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];

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

buttons

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

最佳答案

我认为这是因为您创建了一个 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];

关于iphone - "Blue box"显示在 iOS 应用程序中的自定义 UIButton 旁边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18923031/

相关文章:

iphone - Spotify/iPod 喜欢现在播放 View

iphone - IOS中的按钮组

ios - 在 iOS 设备上本地保存解析对象

ios - 如何在 iOS Swift 中对 UIView 的不同角应用不同的角半径?

objective-c - 屏幕保护程序中的生涩/抖动(核心)动画?

iphone - 更新底层数据后 UITableView 标题无法正确显示

ios - 对于 iOS 8 中的自定义键盘,我们如何使用长按来删除整个单词?

ios - ReactiveCocoa,RACCommand 显示消息或完成后执行 segue

ios - 如何正确使用 AVPlayer 使其在播放视频前不显示白屏?

ios - 更新 Firebase Messaging 时出现“架构 x86_64 的重复符号”