分类 移动开发 下的文章

ionic开发的几个小坑

之前做个小移动客户端,图方便快捷,使用了ionic来开发,整体还是挺顺畅的,就是不太习惯yong其中碰到一些小坑,
都是一些知道了就很简单,不知道就很蛋疼的东西,所以做个笔记,帮初次接触ionic和angularjs的人省点事儿
1.ionic中的CORS(跨域)问题
这个问题一般刚接触ionic的都会遇到,在浏览器中通过ionic serve调试的时候,请求api时会报错

XMLHttpRequest cannot load http://localhost:8080/api/p/1. No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost:8100' is therefore not allowed
access.

- 阅读剩余部分 -

自定义UITableViewCell的高度自适应

项目里需要实现UITableView的Cell的高度自适应,google后发现都是基于默认cell的处理,对于自定义的UITableViewCell没有效果,稍微研究了一下代码,发现,关键还是在计算UILabel的高度上,于是稍微对网上现成的代码做了写修改,实现了需要的功能。
要实现的效果如下:

donelist.png

自定义的cell也很简单,一排label,简单的表格效果:

celldemo.png

简单贴一下关键代码,做为备忘:

1、设置全局变量来保存每行高度,目的是避免重复计算高度

  1. @property (nonatomic, retain) NSMutableArray *cellHeightList;
  2. @synthesize cellHeightList;
  3. - (void)viewDidLoad
  4. {
  5. [super viewDidLoad];
  6. //初始化
  7. self.cellHeightList = [[NSMutableArray alloc] init];
  8. }

<br/>
2、计算每行cell高度,并保存高度列表
<br/>

  1. - (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  2. {
  3. int row = [indexPath row];
  4. //设置字体信息
  5. UIFont *textfont15 = [UIFont systemFontOfSize:15];
  6. //选取几个可能内容比较多的label值
  7. Category *category = (Category *)[self.personList objectAtIndex:indexPath.section];
  8. NSDictionary *rowData = [category.list objectAtIndex:row];
  9. NSString *pnowContent = [rowData objectForKey:@"ppositionnow"];
  10. NSString *pfurContent = [rowData objectForKey:@"ppositionfur"];
  11. NSString *pcancelContent = [rowData objectForKey:@"ppositioncancel"];
  12. NSString *degreeContent = [rowData objectForKey:@"pdegree"];
  13. NSString *infoContent = [rowData objectForKey:@"potherinfo"];
  14. // 分别计算显示这些内容的几个label所需要的最小尺寸
  15. //169.0f;104.0f;145.0f为label的宽度
  16. CGSize pnowsize = [pnowContent sizeWithFont:textfont15 constrainedToSize:CGSizeMake(168.0f, 1000.0f) lineBreakMode:NSLineBreakByWordWrapping];
  17. CGSize pfursize = [pfurContent sizeWithFont:textfont15 constrainedToSize:CGSizeMake(168.0f, 1000.0f) lineBreakMode:NSLineBreakByWordWrapping];
  18. CGSize pcansize = [pcancelContent sizeWithFont:textfont15 constrainedToSize:CGSizeMake(168.0f, 1000.0f) lineBreakMode:NSLineBreakByWordWrapping];
  19. CGSize degsize = [degreeContent sizeWithFont:textfont15 constrainedToSize:CGSizeMake(104.0f, 1000.0f) lineBreakMode:NSLineBreakByWordWrapping];
  20. CGSize infosize = [infoContent sizeWithFont:textfont15 constrainedToSize:CGSizeMake(145.0f, 1000.0f) lineBreakMode:NSLineBreakByWordWrapping];
  21. //保存不同label高度值
  22. NSMutableArray *heightArray = [[NSMutableArray alloc] initWithCapacity:5];
  23. [heightArray addObject:[NSNumber numberWithFloat:pnowsize.height]];
  24. [heightArray addObject:[NSNumber numberWithFloat:pfursize.height]];
  25. [heightArray addObject:[NSNumber numberWithFloat:pcansize.height]];
  26. [heightArray addObject:[NSNumber numberWithFloat:degsize.height]];
  27. [heightArray addObject:[NSNumber numberWithFloat:infosize.height]];
  28. //初始化最大高度值
  29. NSNumber *max_height = [NSNumber numberWithInt:50];
  30. //比较,找出最大高度做为cell的高度
  31. for (int i=0;i<[heightArray count];i++){
  32. if ([[heightArray objectAtIndex:i] intValue]>[max_height intValue]) {
  33. max_height = [heightArray objectAtIndex:i];
  34. }
  35. }
  36. //保存cell高度到全局变量
  37. [self.cellHeightList addObject:[NSNumber numberWithFloat:[max_height floatValue]+30]];
  38. return [max_height floatValue]+30.0;
  39. }

<br/>
3、设置cell内UILabel的高度
<br/>

  1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2. {
  3. ……
  4. NSDictionary *rowData = [category.list objectAtIndex:nowrow];
  5. NSString *pnameContent = [rowData objectForKey:@"pname"];
  6. NSString *pnowContent = [rowData objectForKey:@"ppositionnow"];
  7. NSString *pfurContent = [rowData objectForKey:@"ppositionfur"];
  8. NSString *pcancelContent = [rowData objectForKey:@"ppositioncancel"];
  9. NSString *genderContent = [rowData objectForKey:@"pgender"];
  10. NSString *degreeContent = [rowData objectForKey:@"pdegree"];
  11. NSString *birthContent = [rowData objectForKey:@"pbirth"];
  12. NSString *partyContent = [rowData objectForKey:@"pparty"];
  13. NSString *infoContent = [rowData objectForKey:@"potherinfo"];
  14. //获取当前cell高度
  15. float labelHeight = [[self.cellHeightList objectAtIndex:nowrow] floatValue];
  16. //当前label信息
  17. CGRect pnameFrame = cell.PersonNameLabel.frame;
  18. CGRect pnowFrame = cell.PositionNowLabel.frame;
  19. CGRect pfurFrame = cell.PositionFurLabel.frame;
  20. CGRect pcanFrame = cell.PositionCancelLabel.frame;
  21. CGRect genderFrame = cell.GenderLabel.frame;
  22. CGRect degreeFrame = cell.DegreeLabel.frame;
  23. CGRect birthFrame = cell.BirthLabel.frame;
  24. CGRect partyFrame = cell.PartyLabel.frame;
  25. CGRect otherFrame = cell.OtherLabel.frame;
  26. //修改label的高度
  27. pnameFrame.size.height = labelHeight;
  28. pnowFrame.size.height = labelHeight;
  29. pfurFrame.size.height = labelHeight;
  30. pcanFrame.size.height = labelHeight;
  31. genderFrame.size.height = labelHeight;
  32. degreeFrame.size.height = labelHeight;
  33. birthFrame.size.height = labelHeight;
  34. partyFrame.size.height = labelHeight;
  35. otherFrame.size.height = labelHeight;
  36. //更新label的信息
  37. cell.PersonNameLabel.frame = pnameFrame;
  38. cell.PositionNowLabel.frame = pnowFrame;
  39. cell.PositionFurLabel.frame = pfurFrame;
  40. cell.PositionCancelLabel.frame = pcanFrame;
  41. cell.GenderLabel.frame = genderFrame;
  42. cell.DegreeLabel.frame = degreeFrame;
  43. cell.BirthLabel.frame = birthFrame;
  44. cell.PartyLabel.frame = partyFrame;
  45. cell.OtherLabel.frame = otherFrame;
  46. //设置label内容
  47. cell.PersonNameLabel.text = pnameContent;
  48. cell.PositionNowLabel.text = pnowContent;
  49. cell.PositionFurLabel.text = pfurContent;
  50. cell.PositionCancelLabel.text = pcancelContent;
  51. cell.GenderLabel.text = genderContent;
  52. cell.DegreeLabel.text = degreeContent;
  53. cell.BirthLabel.text = birthContent;
  54. cell.PartyLabel.text = partyContent;
  55. cell.OtherLabel.text = infoContent;
  56. ……
  57. }

<br/>
编译运行,搞定……

mac截图快捷键

我会告诉你在这之前我都是先打开“预览”,然后再通过点击来选择截图功能的?

  1. 1. Command-Shift-3: 将整个屏幕拍下并保存到桌面。
  2.  
  3. 2. Command-Shift-Control-3:将整个屏幕拍下并保存到剪贴板(Clipboard),然后Command+V直接粘贴到如Photoshopppt等软件中编辑。
  4.  
  5. 3. Command-Shift-4:将屏幕的一部分拍下并保存到桌面。按下这个组合键后,光标会变为一个十字,你可以拖拉来选取拍摄区域。
  6.  
  7. 4. Command-Shift-Control-4:将屏幕的一部分拍下并保存到剪贴板。
  8.  
  9. 5. Command-Shift-4再按空格键:这时光标会变为一个照相机图标,点击可拍下当前窗口或菜单或Dock以及图标等,只要将照相机图标移动到不同区域(有效区域会显示为浅蓝色)点击。
  10.  
  11. 6. Command-Shift-Control-4再按空格键:将选取的窗口或其他区域的快照保存到剪贴板。

- 阅读剩余部分 -

热评文章

最新文章

最近回复

归档

其它