FLEXArgumentInputTextView.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // FLEXArgumentInputTextView.m
  3. // FLEXInjected
  4. //
  5. // Created by Ryan Olson on 6/15/14.
  6. //
  7. //
  8. #import "FLEXArgumentInputTextView.h"
  9. #import "FLEXUtility.h"
  10. @interface FLEXArgumentInputTextView () <UITextViewDelegate>
  11. @property (nonatomic, strong) UITextView *inputTextView;
  12. @property (nonatomic, readonly) NSUInteger numberOfInputLines;
  13. @end
  14. @implementation FLEXArgumentInputTextView
  15. - (instancetype)initWithArgumentTypeEncoding:(const char *)typeEncoding
  16. {
  17. self = [super initWithArgumentTypeEncoding:typeEncoding];
  18. if (self) {
  19. self.inputTextView = [[UITextView alloc] init];
  20. self.inputTextView.font = [[self class] inputFont];
  21. self.inputTextView.backgroundColor = [UIColor whiteColor];
  22. self.inputTextView.layer.borderColor = [[UIColor blackColor] CGColor];
  23. self.inputTextView.layer.borderWidth = 1.0;
  24. self.inputTextView.autocapitalizationType = UITextAutocapitalizationTypeNone;
  25. self.inputTextView.autocorrectionType = UITextAutocorrectionTypeNo;
  26. self.inputTextView.delegate = self;
  27. [self addSubview:self.inputTextView];
  28. }
  29. return self;
  30. }
  31. #pragma mark - Text View Changes
  32. - (void)textViewDidChange:(UITextView *)textView
  33. {
  34. [self.delegate argumentInputViewValueDidChange:self];
  35. }
  36. #pragma mark - Layout and Sizing
  37. - (void)layoutSubviews
  38. {
  39. [super layoutSubviews];
  40. self.inputTextView.frame = CGRectMake(0, self.topInputFieldVerticalLayoutGuide, self.bounds.size.width, [self inputTextViewHeight]);
  41. }
  42. - (NSUInteger)numberOfInputLines
  43. {
  44. NSUInteger numberOfInputLines = 0;
  45. switch (self.targetSize) {
  46. case FLEXArgumentInputViewSizeDefault:
  47. numberOfInputLines = 2;
  48. break;
  49. case FLEXArgumentInputViewSizeLarge:
  50. numberOfInputLines = 8;
  51. break;
  52. }
  53. return numberOfInputLines;
  54. }
  55. - (CGFloat)inputTextViewHeight
  56. {
  57. return ceil([[self class] inputFont].lineHeight * self.numberOfInputLines) + 16.0;
  58. }
  59. - (CGSize)sizeThatFits:(CGSize)size
  60. {
  61. CGSize fitSize = [super sizeThatFits:size];
  62. fitSize.height += [self inputTextViewHeight];
  63. return fitSize;
  64. }
  65. #pragma mark - Class Helpers
  66. + (UIFont *)inputFont
  67. {
  68. return [FLEXUtility defaultFontOfSize:14.0];
  69. }
  70. @end