TitleViewCell.m 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //
  2. // TitleViewCell.m
  3. // BuguLive
  4. //
  5. // Created by fanwe2014 on 16/11/7.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "TitleViewCell.h"
  9. @implementation TitleViewCell
  10. - (void)awakeFromNib
  11. {
  12. [super awakeFromNib];
  13. self.titleLabel.textColor = kAppGrayColor1;
  14. self.titleLabel.numberOfLines = 0;
  15. [self.titleLabel sizeToFit];
  16. }
  17. - (CGFloat)setCellWithString:(NSString *)string
  18. {
  19. NSString *nameString = [NSString stringWithFormat:@"%@",string];;
  20. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:nameString];
  21. [attr setAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14.0]} range:NSMakeRange(0,nameString.length)];
  22. NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:14]};
  23. CGFloat height = [nameString boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 10, 10000000) options:NSStringDrawingTruncatesLastVisibleLine |NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attributes context:nil].size.height;
  24. CGRect rect = self.titleLabel.frame;
  25. rect = CGRectMake(10, 5, kScreenW-10, height+10);
  26. self.titleLabel.frame = rect;
  27. self.titleLabel.attributedText = attr;
  28. return height+20;
  29. }
  30. @end