zoukankan      html  css  js  c++  java
  • iOS代码实现九宫格

    #define ScreenW [UIScreen mainScreen].bounds.size.width
    #define ScreenH [UIScreen mainScreen].bounds.size.height
     1 // 数据
     2     NSArray *images = @[@"publish-boke", @"publish-weixin", @"publish-QQ", @"publish-offline"];
     3     NSArray *titles = @[@"发博客", @"发微信", @"发QQ",@"离线下载"];
     4     
     5     // 中间的6个按钮
     6     int maxCols = 3;
     7     CGFloat buttonW = 72;
     8     CGFloat buttonH = buttonW + 30;
     9     CGFloat buttonStartY = (ScreenH - 2 * buttonH) * 0.5;
    10     CGFloat buttonStartX = 20;
    11     CGFloat xMargin = (ScreenW - 2 * buttonStartX - maxCols * buttonW) / (maxCols - 1);
    12     for (int i = 0; i<images.count; i++) {
    13         VerticalButton *button = [[VerticalButton alloc] init];
    14         // 设置内容
    15         button.titleLabel.font = [UIFont systemFontOfSize:14];
    16         [button setTitle:titles[i] forState:UIControlStateNormal];
    17         [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    18         [button setImage:[UIImage imageNamed:images[i]] forState:UIControlStateNormal];
    19         
    20         // 设置frame
    21         button.width = buttonW;
    22         button.height = buttonH;
    23         int row = i / maxCols;
    24         int col = i % maxCols;
    25         button.x = buttonStartX + col * (xMargin + buttonW);
    26         button.y = buttonStartY + row * buttonH;
    27         [self.view addSubview:button];
    28     }
  • 相关阅读:
    CocoaPods
    第一篇 理论 1.7 精进-正念-正知,如理作意和觉察力
    构架稳定与可扩展的优惠券系统
    一个产品从0到1的过程
    实现实时定位
    征信比拼重点是数据和连接
    黑产
    爬虫有什么用
    爬虫应用
    甘蔗理论
  • 原文地址:https://www.cnblogs.com/HJiang/p/5991237.html
Copyright © 2011-2022 走看看