问题描述
我正在使用UIBmageView和UIButton一大堆。所以,我创建了一个自定义类来永久地将这两个结合起来,使事情变得更简单一些。一切顺利,直到我决定实现 - (id)initWithObject:(AUIImageViewButton *)imageViewButton。
I am using UIImageView's with UIButtons a whole bunch. So, I created a custom class to permanently marry these two an make things a little simpler. It all works well until I decided to implement -(id)initWithObject:(AUIImageViewButton *) imageViewButton.
显然我需要从传递的imageViewButton对象中复制所有相关属性。 UIImageView根本没有问题。这样的事情处理它:
Clearly I need to copy all relevant properties from the imageViewButton object being passed. The UIImageView is not problematic at all. Something like this deals with it:
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]; //
大部分按钮内容也随时可用:
Most of the button stuff is also readily available:
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方法。
I am having a little trouble figuring out how to get all the data for the addTarget:action:forControlEvents method.
查看文档我可以看到我可以使用UIControl的allControlEvents和allTargets方法。我现在就深入研究它,看看我能遇到多少麻烦。我不确定的是行动。
Looking at the docs I can see that I might be able to use UIControl's allControlEvents and allTargets methods. I'll dig into that right now and see how much trouble I can get into. The one I am not sure about is the action.
任何人都可以向我推进正确的方向吗?
Can anyone give me a shove in the right direction?
谢谢,
-Martin
推荐答案
UIControl的 allTargets
和 allControlEvents
是开始的方式。最后一块拼图是 actionsForTarget:forControlEvent:
,为每个目标和事件调用一次。
UIControl's allTargets
and allControlEvents
are the way to start. The final piece of the puzzle is actionsForTarget:forControlEvent:
, call it once for each target and event.
这篇关于如何获得UIButton目标,动作和控制事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!