暫無描述

FKCirclePublicTextCell.m 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // FKCirclePublicTextCell.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 16/6/8.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKCirclePublicTextCell.h"
  9. #import "FKCirclePublicTextItem.h"
  10. @implementation FKCirclePublicTextCell
  11. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  12. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  13. self.selectionStyle = UITableViewCellSelectionStyleNone;
  14. [self addAllSubviews];
  15. }
  16. return self;
  17. }
  18. #pragma mark - API
  19. - (void)configWith:(id)item {
  20. if ([item isKindOfClass:[FKCirclePublicTextItem class]]) {
  21. FKCirclePublicTextItem *textItem = (FKCirclePublicTextItem *)item;
  22. self.textView.text = textItem.text;
  23. self.textView.placeholder = textItem.palceholder;
  24. self.textView.placeholderColor = UIColorFromRGB(0x999999);
  25. }
  26. }
  27. #pragma mark - Layout
  28. - (void)addAllSubviews {
  29. [self.contentView addSubview:self.textView];
  30. [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
  31. make.left.equalTo(self.contentView).offset(12);
  32. make.top.equalTo(self.contentView).offset(0);
  33. make.right.equalTo(self.contentView).offset(-12);
  34. make.bottom.equalTo(self.contentView).offset(0);
  35. }];
  36. }
  37. #pragma mark - Method
  38. + (CGFloat)heightWith:(id)item {
  39. CGSize size;
  40. if ([item isKindOfClass:[FKCirclePublicTextItem class]]) {
  41. FKCirclePublicTextItem *textItem = (FKCirclePublicTextItem*)item;
  42. UITextView *textView = [[UITextView alloc] init];
  43. textView.font = [UIFont systemFontOfSize:14];
  44. textView.text = textItem.text;
  45. CGFloat width = (UISCREENWIDTH - 12 - 12);
  46. size = [textView sizeThatFits:CGSizeMake(width, MAXFLOAT)];
  47. }
  48. return (MAX(54, ceilf(size.height)) + 1);
  49. }
  50. #pragma mark - Property
  51. - (UIPlaceHolderTextView *)textView {
  52. if (!_textView) {
  53. _textView = [[UIPlaceHolderTextView alloc] init];
  54. _textView.font = [UIFont systemFontOfSize:14];
  55. _textView.textColor = UIColorFromRGB(0x666666);
  56. _textView.scrollEnabled = NO;
  57. _textView.returnKeyType = UIReturnKeyDone;
  58. }
  59. return _textView;
  60. }
  61. @end