AJ学IOS(05)UI之360等下载管理器九宫格UI
2015-11-29 00:40
489 查看
AJ分享,必须精品
主要是完成了九宫格UI的搭建
没有通过双层for循环换行,而是通过第几个然后判断他的行和列 来定位他的xy坐标完成
012 在第一行:相当于i/kColCount
//行 一行:012 二行:345 三行:678
int row = i/kColCount;
//列 一列:036 二列:147
int col = i%kColCount;
icon.image = [UIImage imageNamed:dict[@”icon”]];
icon.contentMode = UIViewContentModeScaleAspectFit;
button字体设置
先看效果
主要是完成了九宫格UI的搭建
代码
[code]- (void)viewDidLoad { [super viewDidLoad]; //九宫格中每个格子的宽 #define kAppViewW 80 //九宫格中每个格子的高 #define kAppViewH 90 ////九宫格中有多少个格子 #define kColCount 3 //九宫格中第一行距离屏幕最上边距离 #define kStartY 20 /* 思路:将三个控件放到一个view中 没有通过双层for循环换行,而是通过第几个然后判断他的行和列 来定位他的xy坐标完成 012 在第一行:相当于i/kColCount //行 一行:012 二行:345 三行:678 int row = i/kColCount; //列 一列:036 二列:147 int col = i%kColCount; */ //每行的间隔 CGFloat marginX = (self.view.frame.size.width - kColCount*kAppViewW)/(kColCount+1); //每列的间隔 CGFloat marginY = 10; for (int i=0; i<12; i++) { //行 一行:012 二行:345 三行:678 int row = i/kColCount; //列 一列:036 二列:147 int col = i%kColCount; CGFloat x = marginX + col*(marginX+kAppViewW);//每个view的X坐标 CGFloat y = kStartY + +marginY + row * (marginY + kAppViewH);//每个view的Y坐标 UIView *appView = [[UIView alloc] initWithFrame:CGRectMake(x, y ,kAppViewW, kAppViewH)]; [self.view addSubview:appView]; //实现视图内部细节 NSDictionary *dict = self.appList[i];//得到appList中的每一个字典元素(图像 标题 按钮图像) //UIImageView:应用程序图片 UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kAppViewW, 50)]; // icon .backgroundColor = [UIColor redColor]; icon.image = [UIImage imageNamed:dict[@"icon"]];//设置图片 //设置图片填充模式 icon.contentMode = UIViewContentModeScaleAspectFit;//fill的会更大 [appView addSubview:icon]; //UILabel:应用程序名称 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(icon.frame), kAppViewW, 20)]; label.text = dict[@"name"]; label.font = [UIFont systemFontOfSize:13.0]; label.textAlignment = NSTextAlignmentCenter; [appView addSubview:label]; //UIButton:应用程序下载按钮 UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(label.frame), kAppViewW, 20)]; [button setBackgroundImage:[UIImage imageNamed:@"buttongreen"] forState:UIControlStateNormal]; [button setBackgroundImage:[UIImage imageNamed:@"buttongreen_highlighted"] forState:UIControlStateHighlighted]; [button setTitle:@"下载" forState:UIControlStateNormal]; // *** 一定不要使用以下方法,修改按钮标题 // button.titleLabel.text = @"aaa"; // 修改字体(titleLabel是只读的) // readonly表示不允许修改titleLabel的指针,但是可以修改label的字体 // 提示:按钮的字体是不区分状态的! button.titleLabel.font = [UIFont systemFontOfSize:12.0]; [appView addSubview:button]; } }
思路
思路:将三个控件放到一个view中没有通过双层for循环换行,而是通过第几个然后判断他的行和列 来定位他的xy坐标完成
012 在第一行:相当于i/kColCount
//行 一行:012 二行:345 三行:678
int row = i/kColCount;
//列 一列:036 二列:147
int col = i%kColCount;
算法分析图
注意点
设置图片与设置图片铺垫样子的时候有点不同,如果最后设置成UIViewContentModeScaleAspectFit的话会超出定义的边框,按照原来像素大小来布置。icon.image = [UIImage imageNamed:dict[@”icon”]];
icon.contentMode = UIViewContentModeScaleAspectFit;
UILabel;UIButton的字体设置
[code] //设置标题 label.text = dict[@"name"]; //设置字体大小 label.font = [UIFont systemFontOfSize:13.0]; //设置Label居中 label.textAlignment = NSTextAlignmentCenter;
button字体设置
[code][button setTitle:@"下载" forState:UIControlStateNormal]; // *** 一定不要使用以下方法,修改按钮标题 // button.titleLabel.text = @"aaa"; // 修改字体(titleLabel是只读的) // readonly表示不允许修改titleLabel的指针,但是可以修改label的字体 // 提示:按钮的字体是不区分状态的! button.titleLabel.font = [UIFont systemFontOfSize:12.0];
相关文章推荐
- AJ学IOS(04)UI之半小时搞定Tom猫
- AJ学IOS(03)UI之纯代码实现UI——图片查看器
- AJ学IOS(02)UI之按钮操作 点击变换 移动 放大缩小 旋转
- SQL Server ->> Online Index Rebuilding(联机索引重建)
- iOS开发>学无止境 - 五种创建UIImage的类方法
- iOS开发>学无止境 - 截取UIImage指定大小区域
- iOS开发>学无止境 - UIImage等比缩放
- iOS开发>学无止境 - 自定义导航按钮UIBarButtonItem
- 阿里巴巴内部资料 | 交互设计全档案
- UIImagePickerController
- Vue.js 的一些资源索引
- Android详细的对话框AlertDialog.Builder使用方法
- iOS开发>学无止境 - 多个UIImage合并成一个UIImage
- iOS开发>学无止境 - UIImage图片无限滚动的实现
- iOS开发>学无止境 - UIStackView如何让你的开发更简单
- iOS开发>学无止境 - UITablView上下滑动控制底部按钮的出现和消失
- EasyUI添加tab页签
- iOS开发>学无止境 - UICollectionView自定义布局之风火轮[译]
- 由position: sticky; 想到的
- pat 1007. Maximum Subsequence Sum (25)