zoukankan      html  css  js  c++  java
  • 按钮创建

    //button创建
    -(void)initUI
    {
        NSArray *imageArr =[NSArray arrayWithObjects:@"hf",@"zfb",@"cft",@"yhk", nil];  //正常状态
        NSArray *hImageArr =[NSArray arrayWithObjects:@"hf0",@"zfb0",@"cft0",@"yhk0", nil];  //高亮
        NSArray *labelArr =[NSArray arrayWithObjects:@"兑换话费",@"支付宝",@"财付通",@"银行卡", nil];  //选项
        
        for (int i=0; i<4; i++)
        {
            UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button setBackgroundImage:[UIImage imageNamed:[imageArr objectAtIndex:i]] forState:UIControlStateNormal];
            [button setBackgroundImage:[UIImage imageNamed:[hImageArr objectAtIndex:i]] forState:UIControlStateHighlighted];
            
            //视图布局
            button.frame = CGRectMake(45+150*i, 100, 142/2,142/2);
            if (i>1)
            {
                button.frame = CGRectMake(45+150*(i-2),260, 142/2,142/2);
            }
            button.tag=i;
            [button addTarget:self action:@selector(buttonClick:) forControlEvents: UIControlEventTouchUpInside];
            [self.view addSubview:button];
            
            UILabel * label=[[UILabel alloc]initWithFrame:CGRectMake(button.frame.origin.x-10,button.frame.origin.y+80 , 100, 30)];
            label.text=[labelArr objectAtIndex:i];
            label.textAlignment=NSTextAlignmentCenter;
            label.backgroundColor=[UIColor clearColor];
            label.textColor=[UIColor blackColor];
            [self.view addSubview:label];
        }
    }
    
    //点击事件
    -(void)buttonClick:(UIButton *)btn
    {
        switch (btn.tag) {
            case 0:
                 NSLog(@"兑换话费");
                break;
             case 1:
                NSLog(@"支付宝");
                break;
            case 2:
                 NSLog(@"财付通");
                break;
            case 3:
                 NSLog(@"银行卡");
                break;
            default:
                break;
        }
    }
    

    对Button进行一次封装  http://blog.csdn.net/duxinfeng2010/article/details/8687203

  • 相关阅读:
    stl_hash_set.h
    stl_hash_map.h
    stl_algobase.h
    stl_relops.h
    stl_algo.h
    VC6常用插件
    visual assist(VA)设置快捷键(其它安装的插件设置快捷键也在这里)
    SVN常用命令说明
    Android 调用相册 拍照 实现系统控件缩放 切割图片
    Android 一个3D相册源码
  • 原文地址:https://www.cnblogs.com/hl666/p/3710864.html
Copyright © 2011-2022 走看看