FeedbackBodyView.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 UILabel *tipsLabel;
  10. @property (weak, nonatomic) IBOutlet UITextField *contactField;
  11. @property (weak, nonatomic) IBOutlet UILabel *wxContract;
  12. @property (weak, nonatomic) IBOutlet UILabel *emailContract;
  13. @property (weak, nonatomic) IBOutlet UIButton *sureButton;
  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 = @"邮箱:klx@kulexiu999.onexmail.com";
  25. }
  26. else {
  27. orgEmail = [NSString stringWithFormat:@"邮箱:%@",orgEmail];
  28. }
  29. _emailContract.text = orgEmail;
  30. }
  31. - (void)configPhone:(NSString *)phone email:(NSString *)email {
  32. if (![NSString isEmptyString:email]) {
  33. self.emailContract.text = [NSString stringWithFormat:@"邮箱:%@", email];
  34. }
  35. }
  36. + (instancetype)shareInstance {
  37. FeedbackBodyView *view = [[[NSBundle mainBundle] loadNibNamed:@"FeedbackBodyView" owner:nil options:nil] firstObject];
  38. return view;
  39. }
  40. - (void)submitActionCallback:(SubmitAction)action {
  41. if (action) {
  42. self.action = action;
  43. }
  44. }
  45. - (IBAction)submitAction:(id)sender {
  46. [self endEditing:YES];
  47. if (self.action) {
  48. if ([NSString isEmptyString:self.inputText.text]) {
  49. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请输入反馈意见"];
  50. return;
  51. }
  52. // if ([NSString isEmptyString:self.contactField.text]) {
  53. // [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请输入您的联系方式"];
  54. // return;
  55. // }
  56. self.action(self.inputText.text, self.contactField.text);
  57. }
  58. }
  59. #pragma mark ---- delegate
  60. - (void)textViewDidBeginEditing:(UITextView *)textView {
  61. self.tipsLabel.hidden = YES;
  62. }
  63. - (void)textViewDidEndEditing:(UITextView *)textView {
  64. if ([NSString isEmptyString:textView.text]) {
  65. self.tipsLabel.hidden = NO;
  66. }
  67. }
  68. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
  69. if ([text isEqualToString:@"\n"]) {
  70. [self endEditing:YES];
  71. return YES;
  72. }
  73. if ([text isEqualToString:@""]) {
  74. return YES;
  75. }
  76. return YES;
  77. }
  78. - (BOOL)textViewShouldEndEditing:(UITextView *)textView {
  79. [self endEditing:YES];
  80. return YES;
  81. }
  82. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  83. [self endEditing:YES];
  84. }
  85. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  86. if ([string isEqualToString:@"\n"]) {
  87. [self endEditing:YES];
  88. return YES;
  89. }
  90. return YES;
  91. }
  92. - (void)setButtonColor:(UIColor *)buttonColor {
  93. _buttonColor = buttonColor;
  94. if (buttonColor) {
  95. [self.sureButton setBackgroundColor:buttonColor];
  96. }
  97. }
  98. /*
  99. // Only override drawRect: if you perform custom drawing.
  100. // An empty implementation adversely affects performance during animation.
  101. - (void)drawRect:(CGRect)rect {
  102. // Drawing code
  103. }
  104. */
  105. @end