码迷,mamicode.com
首页 > 其他好文 > 详细

UIButton 的使用

时间:2015-07-14 10:07:30      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:uibutton   代码   

直接上代码:

/*
        UIButton 的使用
     */

    UIButton *aButton = [UIButton buttonWithType: UIButtonTypeCustom];
    aButton.frame = CGRectMake(0, 0, 150, 100);
    aButton.center = self.window.center;

    //为按钮在不同状态下添加标题
    [aButton setTitle:@"click" forState:UIControlStateNormal];
    [aButton setTitle:@"gui" forState:UIControlStateHighlighted];
    //设置不同状态下按钮上文本的颜色
    [aButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal] ;
    [aButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted] ;
    //设置按钮上文本字体的大小
    aButton.titleLabel.font = [UIFont systemFontOfSize:45];
//  默认添加为NO(按钮是否显示光亮效果)
    aButton.showsTouchWhenHighlighted = YES ;


    //给按钮在不同状态下添加不同样式的图片
//    [aButton setImage:[UIImage imageNamed:@"after.png"] forState:UIControlStateNormal];
//    [aButton setImage:[UIImage imageNamed:@"fornt.png"] forState:UIControlStateHighlighted];
//   
    [self.window addSubview:aButton];


    //给按钮添加点击的响应方法(即按钮事件)
    //当按钮点击时根据控制事件的类型,让对应对象 target 去执行自己的方法 action,如果方法有参数,则方法内部传回的参数是当前被点击的按钮对象本身!按钮常用的事件类型有 TouchUpInside (抬起才响应) TouchDown (按下即响应)。
    [aButton addTarget:self action:@selector(handleButtonAction:) forControlEvents:UIControlEventTouchDown];

版权声明:本文为博主原创文章,未经博主允许不得转载。

UIButton 的使用

标签:uibutton   代码   

原文地址:http://blog.csdn.net/zhengang007/article/details/46873041

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!