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

  • 相关阅读:
    ZOJ 1001 A + B Problem
    献给那些心软的人!!
    将表格的数据插入另一个表格
    把链接 显示为方框
    【ibus】设置ibus输入法(pinyin & sunpinyin)
    [Mongo] How to Install Mongo on Debian(不要安装)
    [Sinatra、Mongo] Mongo
    Sinatra+SQLite3+DataMapper
    [sinatra] Sinatra再入门
    [slim] Slim
  • 原文地址:https://www.cnblogs.com/hl666/p/3710864.html
Copyright © 2011-2022 走看看