FeedbackBodyView.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // FeedbackBodyView.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/22.
  6. //
  7. #import "FeedbackBodyView.h"
  8. @interface FeedbackBodyView ()<UITextFieldDelegate, UITextViewDelegate>
  9. @property (weak, nonatomic) IBOutlet UITextView *inputText;
  10. @property (weak, nonatomic) IBOutlet UILabel *tipsLabel;
  11. @property (weak, nonatomic) IBOutlet UITextField *contactField;
  12. @property (weak, nonatomic) IBOutlet UILabel *wxContract;
  13. @property (weak, nonatomic) IBOutlet UILabel *emailContract;
  14. @property (nonatomic, copy) SubmitAction action;
  15. @end
  16. @implementation FeedbackBodyView
  17. - (void)awakeFromNib {
  18. [super awakeFromNib];
  19. self.inputText.delegate = self;
  20. self.contactField.delegate = self;
  21. self.contactField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"您的邮箱或手机号" attributes:@{NSForegroundColorAttributeName:HexRGB(0x777777), NSFontAttributeName:[UIFont systemFontOfSize:14.0f weight:UIFontWeightMedium]}];
  22. NSString *orgEmail = UserDefaultObjectForKey(OrganizationEmailKey);
  23. if ([NSString isEmptyString:orgEmail]) {
  24. orgEmail = @"邮箱:lexiaoyaVIP@163.com";
  25. }
  26. else {
  27. orgEmail = [NSString stringWithFormat:@"邮箱:%@",orgEmail];
  28. }
  29. _emailContract.text = orgEmail;
  30. }
  31. + (instancetype)shareInstance {
  32. FeedbackBodyView *view = [[[NSBundle mainBundle] loadNibNamed:@"FeedbackBodyView" owner:nil options:nil] firstObject];
  33. return view;
  34. }
  35. - (void)submitActionCallback:(SubmitAction)action {
  36. if (action) {
  37. self.action = action;
  38. }
  39. }
  40. - (IBAction)submitAction:(id)sender {
  41. [self endEditing:YES];
  42. if (self.action) {
  43. if ([NSString isEmptyString:self.inputText.text]) {
  44. [self MBPShow:@"请输入反馈意见"];
  45. return;
  46. }
  47. if ([NSString isEmptyString:self.contactField.text]) {
  48. [self MBPShow:@"请输入您的联系方式"];
  49. return;
  50. }
  51. self.action(self.inputText.text, self.contactField.text);
  52. }
  53. }
  54. #pragma mark ---- delegate
  55. - (void)textViewDidBeginEditing:(UITextView *)textView {
  56. self.tipsLabel.hidden = YES;
  57. }
  58. - (void)textViewDidEndEditing:(UITextView *)textView {
  59. if ([NSString isEmptyString:textView.text]) {
  60. self.tipsLabel.hidden = NO;
  61. }
  62. }
  63. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
  64. if ([text isEqualToString:@"\n"]) {
  65. [self endEditing:YES];
  66. return YES;
  67. }
  68. if ([text isEqualToString:@""]) {
  69. return YES;
  70. }
  71. return YES;
  72. }
  73. - (BOOL)textViewShouldEndEditing:(UITextView *)textView {
  74. [self endEditing:YES];
  75. return YES;
  76. }
  77. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  78. [self endEditing:YES];
  79. }
  80. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  81. if ([string isEqualToString:@"\n"]) {
  82. [self endEditing:YES];
  83. return YES;
  84. }
  85. return YES;
  86. }
  87. /*
  88. // Only override drawRect: if you perform custom drawing.
  89. // An empty implementation adversely affects performance during animation.
  90. - (void)drawRect:(CGRect)rect {
  91. // Drawing code
  92. }
  93. */
  94. @end