首页 文章

自定义UIButton背景图像在点击之前不会出现

提问于
浏览
1

在app my中,如果点击某个区域,UIPopoverController会显示UIButtons,点击时会执行某些任务 . UIButtons(称为CableDisconnectButton)是一个子类UIButton,因此我可以为它们添加两个额外的属性 . 我还添加UILabels来检查按钮

但是,按钮的背景图像是不可见的,或者直到我在某个地方点击屏幕才会出现 . UIlabels显示很好,但不是按钮 . 它可以点击UIPopoverController或屏幕上的任何其他位置 . 一旦我第一次点击,按钮将一直存在,直到应用程序关闭 . 所以,这只发生在发布之后,直到我第一次打开UIPopover . 在打开弹出窗口之前我点了很多次 .

按钮的功能和其他一切工作正常,但背景图像隐藏在第一次启动时,我不知道为什么 .

这是我创建按钮和UILabel的方法:

//create custom button
CableDisconnectButton *removeConnectionButton = [CableDisconnectButton buttonWithType:UIButtonTypeCustom];
removeConnectionButton.frame = CGRectMake(x, y, 190, 80);
removeConnectionButton.backgroundColor = [UIColor clearColor];
[removeConnectionButton setBackgroundImage:[UIImage imageNamed:@"images/cable_disconnect_button.png"] forState:UIControlStateNormal];
[removeConnectionButton setBackgroundImage:[UIImage imageNamed:@"images/cable_disconnect_button_over.png"] forState:UIControlStateHighlighted];

//set input and output jacks to button properties
removeConnectionButton.inputJack = inputJack;
removeConnectionButton.outputJack = self.outputJackView;

//add action to button
[removeConnectionButton addTarget:self action:@selector(removeConnectionButtonTarget:) forControlEvents:UIControlEventTouchUpInside];

//create label for output
UILabel *outputConnectionLabel = [[UILabel alloc] initWithFrame:CGRectMake(x+18, y+5, 180, 22)];
outputConnectionLabel.backgroundColor = [UIColor clearColor];
outputConnectionLabel.textColor = [UIColor whiteColor];
outputConnectionLabel.text = self.outputJackView.jackDisplayName;
outputConnectionLabel.font = [UIFont systemFontOfSize:16];

//add subviews
[self addSubview:removeConnectionButton];
[self addSubview:outputConnectionLabel];

我试图添加一个常规的,非自定义的UIButton,它没有水龙头 . 我怀疑它可能与子类UIButton有关,但我不确定为什么 . 添加到UIButton的额外属性是对其功能至关重要的字符串,不能省略 .

1 回答

  • 0

    在我的 table 上打了几天之后,我跑进了“Clean Build Folder”选项 . 我已经清理了很多次项目,但是没有注意到“Clean Build Folder” . 要执行此操作,只需按住Option键,单击菜单中的Product并选择Clean Build Folder .

    所以,如果您的应用程序没有按照应有的方式运行,并且没有任何意义,请尝试此操作 .

相关问题