zoukankan      html  css  js  c++  java
  • ios 常用功能(三)

    批量创建按钮

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        NSInteger total = 9;  //数量
        NSInteger btnWidth = 80;//按钮宽
        NSInteger btnHeight = 30;//按钮高
        NSInteger heightSpace = 15;//按钮行间距
        NSInteger widthSpace = 15;//按钮列间距
        NSInteger btnX = 30;//按钮X起点坐标
        NSInteger btnY = 189;//按钮Y起点坐标
        
        for (int i=0;i<total;i++) {
            UIButton *btns = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            [btns setBackgroundColor:[UIColor whiteColor]];
            [btns setTag:i+1];//设置按钮Tag
            [btns addTarget:self action:@selector(btnsAction:) forControlEvents:UIControlEventTouchUpInside];
            
            CGRect frame;
            frame.origin.x = (i%3)*(btnWidth+widthSpace)+btnX;
            frame.origin.y = (i/3)*(btnHeight+heightSpace)+btnY;
           //frame.origin.x = btnX;
           // frame.origin.y = i*(btnHeight+heightSpace)+btnY;
    
            frame.size.width = btnWidth;
            frame.size.height = btnHeight;
            [btns setFrame:frame];
            [self.view addSubview:btns];
        }
    }
    

     

    ios选择框

    -(void)checkboxClick:(UIButton *)btn
    {
        btn.selected = !btn.selected;
    }
    
    
    - (void)viewDidLoad {
    UIButton *checkbox = [UIButton buttonWithType:UIButtonTypeCustom];
        
        CGRect checkboxRect = CGRectMake(135,150,36,36);
        [checkbox setFrame:checkboxRect];
        
        [checkbox setImage:[UIImage imageNamed:@"checkbox_off.png"] forState:UIControlStateNormal];
        [checkbox setImage:[UIImage imageNamed:@"checkbox_on.png"] forState:UIControlStateSelected];
        
        [checkbox addTarget:self action:@selector(checkboxClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:checkbox];    
    }
    

      

  • 相关阅读:
    bzoj 1031: [JSOI2007]字符加密Cipher
    python re模块实现计算器
    python sys模块和序列化模块
    python time时间模块
    python 发红包的小程序
    python ranndom模块及生成验证码
    python os模块练习题
    python os模块常用命令
    快速排序,归并排序
    选择排序和插入排序
  • 原文地址:https://www.cnblogs.com/hl666/p/3693322.html
Copyright © 2011-2022 走看看