当我触摸按钮外面并拖动按钮时,如何让UIButton获得功能? [英] How can I make a UIButton get a function when I touch outside the button and drag over the button?

查看:107
本文介绍了当我触摸按钮外面并拖动按钮时,如何让UIButton获得功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个标签和一个按钮如果我触摸按钮外面并在按钮上滑动,则应触发一个事件以在标签字段中显示hello。告诉我该怎么做?

If I had a label and a button If i touch outside the button and swiped over the button then an event should be fired to display "hello" in the label field. tell me how can I do it?

推荐答案

请执行以下步骤。


  1. 在你的XIB文件中取UILabel和UIButton。

  1. Take UILabel and UIButton in your XIB file.

在你的ViewController中将UILabel和UIButton作为IBOutlet。 h文件并获取下面描述的这两个属性。

Take UILabel and UIButton as IBOutlet in your ViewController's .h file and take property of this two described below.

  UILabel *lbl;
  UIButton *btn;
  @property(nonatomic, retain)IBOutlet UILabel *lbl;
  @property(nonatomic, retain)IBOutlet UIButton *btn;


  • 现在从XIB设置UILabel和UIButton的新参考插座,并将UIButton的TouchUpInside链接设置为btnClicked方法。

  • Now set UILabel and UIButton's New Reference outlet from XIB and set UIButton's TouchUpInside link to btnClicked method.

    在.h文件中声明此方法,并在.m文件中实现按钮事件。
    在.h文件中写下

    Declare this method in your .h file and implement it in your .m file for button event. Write this in your .h file

     -(IBAction)btnClicked:(id)sender;
    

    并将此代码放在.m文件中

    and place this code in your .m file

     -(IBAction)btnClicked:(id)sender
     {
          lbl.text = @"Hello";
     }         
    


  • 这篇关于当我触摸按钮外面并拖动按钮时,如何让UIButton获得功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆