アプリ my では、特定の領域をタップすると、クリックすると特定のタスクを実行する UIButtons を備えた UIPopoverController が表示されます。UIButton (CableDisconnectButton と呼ばれる) はサブクラス化された UIButton であるため、2 つのプロパティを追加できます。ボタンの上に移動する 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 に追加される追加のプロパティは、 の機能にとって重要な文字列であり、省略できません。