【问题标题】:"Blue box" showing up next to custom UIButton in iOS appiOS 应用中自定义 UIButton 旁边出现“蓝框”
【发布时间】:2013-09-20 18:00:11
【问题描述】:

我正在开发一个 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];

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

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

【问题讨论】:

    标签: iphone ios objective-c uibutton


    【解决方案1】:

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

    【讨论】:

    • 有效。似乎如果按钮是系统类型,则在选择时会在右上角显示某种圆角矩形。我只是将 IB 中的类型更改为自定义,它工作正常。 +1
    【解决方案2】:

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


    要修复的代码:

    [UIButton buttonWithType:UIButtonTypeCustom];


    要修复的故事板:

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 2014-01-04
        • 1970-01-01
        • 2020-03-09
        • 2017-11-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-08
        相关资源
        最近更新 更多