iOS_九宫格代码
2015-11-24 16:24
387 查看
//假设每行应用的格数 int colums = 3; //获取控制器所管理view的宽度 CGFloat viewWith = self.view.frame.size.width; //设置第一行距离顶部的高度 CGFloat marginTop = 40; //每个应用的宽度和高度 CGFloat appW = 75; CGFloat appH = 90; CGFloat marginX = (viewWith - colums * appW) / (colums + 1); CGFloat marginY = marginX; for (int i = 0; i < self.apps.count; i++) { //创建UIView UIView *appView = [[UIView alloc] init]; //计算每个单元格所在列的索引 int colInx = i % colums; //计算每个单元格所在行的索引 int rowInx = i / colums; //设置UIView属性frame CGFloat appX = marginX + colInx * (appW + marginX); CGFloat appY = marginTop + rowInx * (appH + marginY); appView.frame = CGRectMake(appX, appY, appW, appH); // appView.backgroundColor = [UIColor blueColor]; //设置控件 [self setCompent:appView withAPP:self.apps[i]];
相关文章推荐
- iOS中如何使用PCH文件、修改其相对路径的方法
- iOS深入学习 (Block全面分析)
- iOS --- 自定义过渡
- Runtime的理解
- 使用CocoaPods来管理iOS项目的依赖库
- 如何解决键盘遮挡输入框问题
- iOS消息推送机制
- ios核心动画(基础动画)
- iOS切换window根控制器
- IOS开发笔记之三十——一个double精度导致的bug
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
- iOS--优化--保持界面流畅的技巧
- iOS深入学习(Block全面分析)
- iOS证书
- iOS 的页面刷新技术(block,通知)和MVC模型
- iOS 官方文档CALayer
- iOS之 随笔Xcode7的lipo
- iOS开发 底层抛析运行循环—— RunLoop
- iOS开发学习总结
- IOS 自定义转场动画。