zoukankan      html  css  js  c++  java
  • UIButton

    头文件

    #import <UIKit/UIKit.h>

     

    @interface ViewController : UIViewController

     

    @property (nonatomic,strong) UIButton *myButton;

    @end

     

    实现

     

    #import "ViewController.h"

     

    @interfaceViewController ()

     

    @end

     

    @implementation ViewController

     

    - (void) buttonIsPressed: (UIButton *) paramSender {

        NSLog(@"Button is pressed.");

    }

     

    - (void) buttonIsTapped: (UIButton *) paramSender {

        NSLog(@"Button is tapped.");

    }

     

    - (void)viewDidLoad

    {

        [superviewDidLoad];

        

        UIImage *normalImage = [UIImage imageNamed:@"normalStateImage"];

        UIImage *higthLightImage = [UIImage imageNamed:@"higthLightStateImage"];

        self.myButton = [UIButtonbuttonWithType:UIButtonTypeCustom];  //必须在初始化时为UIButton设置一个type,想用图片时必须是这种type

        self.myButton.frame = CGRectMake(120.0f, 200.0f, 200.0f, 200.0f);

        [self.myButtonsetBackgroundImage:normalImage forState:UIControlStateNormal];

        [self.myButtonsetTitle:@"pressed me"forState:UIControlStateNormal];

        [self.myButtonsetBackgroundImage:higthLightImage forState:UIControlStateHighlighted];

        [self.myButtonsetTitle:@"I'm pressed"forState:UIControlStateHighlighted];

        [self.myButtonaddTarget:selfaction:@selector(buttonIsPressed:) forControlEvents:UIControlEventTouchDown];

        [self.myButtonaddTarget:selfaction:@selector(buttonIsTapped:) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:self.myButton];

    }

     

    - (void)didReceiveMemoryWarning

    {

        [superdidReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

     

    @end

  • 相关阅读:
    jenkins构建时报错
    linux查看系统信息
    去掉jenkins的首页警告
    zabbix_server 报警
    OSI七层模型
    linux时间格式总结
    linux系统 lsof命令详解
    SharePoint 2010 用户权限和权限级别
    Error occurred in deployment step 'Activate Features': Unable to locate the workflow's association data.
    使用 Response.Write 向页面body中输出指定html
  • 原文地址:https://www.cnblogs.com/liuhong/p/3281136.html
Copyright © 2011-2022 走看看