Swift:UIButton与UIView(Swift: UIButton vs UIView)
在Swift中,看起来就像
UIButton
和UIView
可以实现类似的行为。 为了赋予按钮功能,可以调用addGestureRecognizer
,而可以为UIView
调用addGestureRecognizer
。 什么时候应该用于另一个? 特别是当涉及图像时,使用与setImage
配对的UIButton
还是与my_image_view.image = UIImage(...)
配对使用的UIImageView
更好?另外,
UIButton
提供的UIView
不支持什么(反之亦然)? 谢谢!In Swift, it appears as though similar behavior can be achieved from a
UIButton
and aUIView
. To give functionality to a button,addTarget
can be called, whereasaddGestureRecognizer
can be called for aUIView
. When should one be used over another? In particular, when images are involved, is it better to use aUIButton
paired withsetImage
orUIImageView
paired withmy_image_view.image = UIImage(...)
?Additionally, what does a
UIButton
offer that aUIView
doesn't (and vice versa)? Thanks!
原文:https://stackoverflow.com/questions/43126645