循环创建按钮
2016-04-13 17:56
351 查看
CGFloat margin = 22;
CGFloat btnW = 35;
CGFloat btnH = 35;
int cloums = 7;
CGFloat btnLeft = (self.view.frame.size.width - (btnW * cloums) - (cloums - 1) * margin) / 2;
for (int i = 0; i < 30; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
// 行的索引
int colIdx = i % cloums;
// 列的索引
int rowIdx = i / cloums;
CGFloat btnX = btnLeft + colIdx * (btnW + margin);
CGFloat btnY = 0 + rowIdx * (btnH + margin);
button.frame = CGRectMake(btnX, btnY, btnW, btnH);
button.backgroundColor = [UIColor redColor];
[self.view addSubview:button];
}
CGFloat btnW = 35;
CGFloat btnH = 35;
int cloums = 7;
CGFloat btnLeft = (self.view.frame.size.width - (btnW * cloums) - (cloums - 1) * margin) / 2;
for (int i = 0; i < 30; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
// 行的索引
int colIdx = i % cloums;
// 列的索引
int rowIdx = i / cloums;
CGFloat btnX = btnLeft + colIdx * (btnW + margin);
CGFloat btnY = 0 + rowIdx * (btnH + margin);
button.frame = CGRectMake(btnX, btnY, btnW, btnH);
button.backgroundColor = [UIColor redColor];
[self.view addSubview:button];
}
相关文章推荐
- 【qt小贴士】Qt窗口置顶相关
- HBase数据迁移(3)-自己编写MapReduce Job导入数据
- 经典的Paxos算法
- Docker入门--简单使用--RHEL7.2
- RabbitMQ安装
- 【原创】k8s源码分析-----kubelet(8)pod管理
- haproxy 超时自动重发
- 个人知识点总结——Java并发
- 浏览器全屏
- 访问元素的尺寸和坐标
- haproxy 超时自动重发
- haproxy 超时自动重发
- 图片BlendMode 样式
- Java代码优化-在某种情况下避免Map的containsKey方法的使用
- 解决Python UnicodeDecodeError: ‘ascii’ codec can’t decode
- iOS-UIView坐标系转换-convertRect toview
- Android NDK编译系统
- DedeCms 5.7后台去除版权及去除广告链操作详解
- 笔记
- Android实现对图片的缩放、剪切、旋转、存储