UIScrollView在storyboard中的使用數組
UIScrollView在代碼中的使用緩存
// 1.建立一個imageView並設置圖片 UIImage *image = [UIImage imageNamed:@"minion"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; // 2.將imageView添加到scrollView中 [self.scrollView addSubview:imageView]; // 3.設置scrollView的內容尺寸 self.scrollView.contentSize = image.size; // 4.設置偏移量 // 控制內容滾動的位置 // 得知scrollView中滾動的位置 // self.scrollView.contentOffset = CGPointMake(200, 0); // 5.設置內邊距(增長額外的滾動區域) // self.scrollView.contentInset = UIEdgeInsetsMake(100, 0, 0, 0);
UITableView在代碼中的使用框架
步驟:spa
繼承UITabelViewcontrol 默認遵照了兩個協議代理
返回組數 /** * 有多少組,默認是一組(不寫此方法 ) */ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return self.carsGroup.count; }; 返回行數 /** * 每一組有多少行 */ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // 取出模型數組 WWDCarsGroup *group = self.carsGroup[section]; return group.cars.count; } 返回cell(緩存池,設置cell的內容數據) /** * 每一行要顯示的內容 */ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // 定義ID static NSString *ID = @"A"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID]; } // 取出模型數組 WWDCarsGroup *group = self.carsGroup[indexPath.section]; WWDCars *cars = group.cars[indexPath.row]; // 設置數據 cell.textLabel.text = cars.name; cell.imageView.image = [UIImage imageNamed:cars.icon]; return cell; } 註冊(自定義cell) // 註冊 [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([WWDTgCell class]) bundle:nil] forCellReuseIdentifier:tgID]; 緩加載部分 • 系統 #pragma mark - 懶加載 - (NSArray *)herosArr { if (!_herosArr) { // 加載plist文件 NSArray *arr = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"heros.plist" ofType:nil]]; // 遍歷字典數組獲取數組模型 NSMutableArray *temp = [NSMutableArray array]; for (NSDictionary *herosDict in arr) { WWDHeros *heros = [WWDHeros herosWithDictionary:herosDict]; [temp addObject:heros]; } _herosArr = temp; } return _herosArr; } • MJ框架 - (NSArray *)tgs { if (!_tgs) { // NSArray *dictArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"tgs.plist" ofType:nil]]; // _tgs = [WWDTg mj_objectArrayWithKeyValuesArray:dictArray]; _tgs = [WWDTg mj_objectArrayWithFilename:@"tgs.plist"]; } return _tgs; } 返回表頭 /** * 表頭顯示的內容 */ - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { WWDCarsGroup *group = self.carsGroup[section]; return group.title; } 返回表尾 //設置尾部 - (NSString *) tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { return @"小擼怡情,大擼傷身,強擼灰飛煙滅"; } /** * 返回索引條文字 */ - (NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView { // NSMutableArray *temp = [NSMutableArray array]; // for (XMGCarGroup *group in self.carGroups) { // [temp addObject:group.title]; // } // return temp; // 抽取self.carGroups每個元素(XMGCarGroup對象)的title屬性的值,放在新的數組中返回 return [self.carGroups valueForKeyPath:@"title"]; } tableView屬性設置 /********************** 屬性設置 *****************************/ // 設置每一行cell的高度 self.tableView.rowHeight = 100; // 設置每一組頭部的高度 self.tableView.sectionHeaderHeight = 40.0 ; // 設置每一組尾部的高度 self.tableView.sectionFooterHeight = 20.0; // 設置分割線的顏色 self.tableView.separatorColor = [UIColor redColor]; // 設置分割線的樣式 self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; // 設置tableView表頭view self.tableView.tableHeaderView = [[UISwitch alloc] init]; // 設置tableView表尾view self.tableView.tableFooterView = [[UISwitch alloc] init]; /********************** 屬性設置 *****************************/ /********************** 屬性設置 *****************************/ // 設置cell右邊的指示樣式 // UITableViewCellAccessoryNone, // UITableViewCellAccessoryDisclosureIndicator, // UITableViewCellAccessoryDetailDisclosureButton, // UITableViewCellAccessoryCheckmark, // UITableViewCellAccessoryDetailButton cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; // 設置cell右邊的指示控件 // accessoryView的優先級 > accessoryType // cell.accessoryView = [[UISwitch alloc] init]; cell屬性 // 設置cell的選中樣式 // UITableViewCellSelectionStyleNone, // UITableViewCellSelectionStyleBlue, // UITableViewCellSelectionStyleGray, // UITableViewCellSelectionStyleDefault // cell.selectionStyle = UITableViewCellSelectionStyleNone; // 設置cell的背景顏色 cell.backgroundColor = [UIColor magentaColor]; // 設置cell的背景view // backgroundView的優先級 > backgroundColor UIImageView *imageView = [[UIImageView alloc] init]; imageView.image = [UIImage imageNamed:@"12196499,2560,1600"]; cell.backgroundView = imageView; // 設置cell選中的背景view UIView *sg = [[UIView alloc] init]; sg.backgroundColor = [UIColor purpleColor]; cell.selectedBackgroundView = sg;