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];    
    }
    

      

  • 相关阅读:
    1005: [HNOI2008]明明的烦恼
    1006: [HNOI2008]神奇的国度
    1007: [HNOI2008]水平可见直线
    1011: [HNOI2008]遥远的行星
    1025: [SCOI2009]游戏
    HTTP1.0和HTTP1.1的区别
    各排序算法的时间复杂度和空间复杂度
    换钱最少货币数
    矩阵的最小路径和
    背包问题
  • 原文地址:https://www.cnblogs.com/hl666/p/3693322.html
Copyright © 2011-2022 走看看