我使用UIImageView的UIButtons一大堆。所以,我創建了一個自定義類來永久結婚這兩件事情,讓事情變得更簡單。這一切運作良好,直到我決定實施 - (id)initWithObject:(AUIImageViewButton *)imageViewButton。如何獲得UIButton Target,Action和Control事件?
顯然我需要從傳遞的imageViewButton對象中複製所有相關屬性。 UIImageView完全沒有問題。像這樣的東西與它涉及:
imageview = [[UIImageView alloc] initWithFrame:imageViewButton.imageview.frame]; // Copy all relevant data from the source's imageview
[imagebutton.imageview setBackgroundColor:imageViewButton.imageview.backgroundColor]; //
[imagebutton.imageview setImage:imageViewButton.imageview.image]; //
大部分按鈕的東西也一應俱全:
button = [UIButton buttonWithType:imageViewButton.button.buttonType]; // Copy all relevant data from the source's button
button.frame = imageViewButton.imageview.frame; //
[button setTitle:imageViewButton.button.titleLabel.text forState:UIControlStateNormal]; //
button.tag = imageViewButton.button.tag; //
我有一個小麻煩搞清楚如何獲取所有數據的addTarget:動作:forControlEvents方法。
看看文檔,我可以看到我可能能夠使用UIControl的allControlEvents和allTargets方法。我現在將深入研究,看看我可以付出多少麻煩。我不確定的是行動。
任何人都可以給我一個正確的方向推?
感謝,
-Martin
只是檢查,你知道UIButton支持背景圖像(標題文本顯示在頂部)和圖像(沒有標題文本顯示)?你需要什麼UIImageView的功能? – Bogatyr