我試圖使用圖像作爲我的導航欄中的按鈕。按鈕顯示得很好,但它們不響應觸摸事件。以下是我如何設置按鈕:iOS:自定義圖像UIBarButtonItem不響應觸摸
UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow_up_24.png"]];
iv.userInteractionEnabled=YES;
UIBarButtonItem * logoutButton = [[UIBarButtonItem alloc] initWithCustomView:iv ];
logoutButton.target=self;
[email protected](logoutButtonPressed);
我錯過了什麼?
你可以嘗試使用anonther初始化:'*的UIBarButtonItem = logoutButton [的UIBarButtonItem頁頭] initWithImage:[UIImage的imageNamed :@「arrow_up_24.png」] style:UIBarButtonItemStylePlain target:self action:@selector(logoutButtonPressed)];'。 – fguchelaar
問題是這會將圖像置於一個按鈕上。這不是我想要的樣子。我只是想讓圖像本身成爲按鈕(沒有邊框和什麼)。我發佈的代碼看起來是正確的,它只是不會響應觸摸。 –