CommentZzVC.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // CommentZzVC.m
  3. // jiaPei
  4. //
  5. // Created by EchoShacolee on 2017/2/16.
  6. // Copyright © 2017年 JCZ. All rights reserved.
  7. //
  8. #import "CommentZzVC.h"
  9. #import "RatingBar.h"
  10. #import "CommentZzCell.h"
  11. @interface CommentZzVC ()<UITableViewDelegate,UITableViewDataSource>
  12. @property (weak, nonatomic) IBOutlet UIView *ratingBar;
  13. @property (weak, nonatomic) IBOutlet UIView *lableView;
  14. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  15. @property (weak, nonatomic) IBOutlet UIButton *collectionBtn;
  16. @property (weak, nonatomic) IBOutlet UIButton *commentBtn;
  17. @property (nonatomic, retain)NSArray * dataArray;
  18. @end
  19. @implementation CommentZzVC
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. _dataArray = [NSArray new];
  23. _dataArray = @[@"在俄罗斯西伯利亚的东北部,有一个因极寒而闻名的“世界最冷小村庄”奥伊米亚康",
  24. @"我的城市开始下起了雪",
  25. @"我很好奇",
  26. @"在极寒的条件的人们是如何生活的……请不要告诉我是靠爱在生活……",
  27. @"在俄罗斯西伯利亚的东北部,有一个因极寒而闻名的“世界最冷小村庄”奥伊米亚康(Oymyakon)。冬天,长达21小时的黑夜,人们在这几乎感受不到白昼"];
  28. [self myInit];
  29. [self setTitle:@"评论详情"];
  30. self.navigationController.navigationBar.translucent = NO;
  31. [self configNavigationBarDismissNav];
  32. }
  33. - (IBAction)collectionBtnClick:(id)sender {
  34. ShowMsg(@"你知道比悲伤更悲伤的是什么吗?是空欢喜");
  35. }
  36. - (IBAction)commentBtnClick:(id)sender {
  37. ShowMsg(@"正是“要做有趣的人”这一追求的广为流传,使世界上多了好多无趣还很努力的人");
  38. }
  39. -(void)myInit
  40. {
  41. //ratingBar
  42. CGSize size = _ratingBar.frame.size;
  43. RatingBar * starBar = [[RatingBar alloc]initWithFrame:CGRectMake(0, 0, size.width, size.height) Flag:NO];
  44. starBar.starNumber = 3;
  45. starBar.enable = NO;
  46. [_ratingBar addSubview:starBar];
  47. //LableView
  48. NSArray * falseData = @[@"哇,好漂亮",@"非常有礼貌",@"支付申诉",@"哇好漂亮",@"哇,好",@"有礼貌",@"哇有礼貌漂亮",@"漂亮"];
  49. NSArray * falseData2 = @[@"5",@"4",@"88",@"5",@"7",@"78",@"35",@"12"];
  50. UILabel * lable;
  51. CGFloat x = 0;
  52. CGFloat y = 0;
  53. CGFloat w = 0;
  54. CGFloat h = 30;
  55. CGFloat bd = (kSize.width - 20 - 300)/2+5;
  56. // CGFloat bd = (_lableView.size.width - )
  57. for (int i=0;i<falseData.count;i++) {
  58. NSString * contentStr = [NSString stringWithFormat:@" %@ %@ ",falseData[i],falseData2[i]];
  59. CGSize size =[contentStr sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:NormalFont]}];
  60. if (i%3 == 0) {
  61. x = 0;
  62. }else{
  63. x += bd+w;
  64. }
  65. if (i/3 == 0) {
  66. y = 5;
  67. }else{
  68. if (i%3 == 0) {
  69. y += 5+h;
  70. }
  71. }
  72. w = size.width;
  73. lable = [[UILabel alloc]setxywh];
  74. [lable setText:contentStr Font:NormalFont TextColor:titleColor Alignment:NSTextAlignmentCenter];
  75. lable.layer.borderWidth = 0.5;
  76. lable.layer.borderColor = [UIColor grayColor].CGColor;
  77. [_lableView addSubview:lable];
  78. }
  79. //tableView
  80. _tableView.delegate = self;
  81. _tableView.dataSource = self;
  82. [_tableView registerNib:[UINib nibWithNibName:@"CommentZzCell" bundle:nil] forCellReuseIdentifier:@"cellId"];
  83. }
  84. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  85. return _dataArray.count;
  86. }
  87. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  88. CGSize size = [_dataArray[indexPath.row] boundingRectWithSize:CGSizeMake(kSize.width-90, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
  89. return size.height+70+10;//@lee 最后这个加10,我的理解是这个计算的size差了一点类似行间距的东西导致不够显示第二行,估计加5也可以,行数越多,累计误差越大
  90. }
  91. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  92. CommentZzCell * cell = [_tableView dequeueReusableCellWithIdentifier:@"cellId" forIndexPath:indexPath];
  93. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  94. cell.headImgV.image = [UIImage imageNamed:@"zz.jpg"];
  95. cell.nameLab.text = @"陈浩南";
  96. cell.contentLab.text = _dataArray[indexPath.row];
  97. cell.timeLab.text = @"2017-01-23";
  98. return cell;
  99. }
  100. - (void)didReceiveMemoryWarning {
  101. [super didReceiveMemoryWarning];
  102. // Dispose of any resources that can be recreated.
  103. }
  104. /*
  105. #pragma mark - Navigation
  106. // In a storyboard-based application, you will often want to do a little preparation before navigation
  107. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  108. // Get the new view controller using [segue destinationViewController].
  109. // Pass the selected object to the new view controller.
  110. }
  111. */
  112. @end