FeedbackExample.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // FeedbackExample.m
  3. // MiMoLive
  4. //
  5. // 使用示例:如何创建带有蓝色下划线的Feedback文本
  6. //
  7. #import "MOBaseLevelView.h"
  8. @interface FeedbackExample : UIViewController
  9. @end
  10. @implementation FeedbackExample
  11. - (void)viewDidLoad {
  12. [super viewDidLoad];
  13. [self setupExampleLabels];
  14. }
  15. - (void)setupExampleLabels {
  16. NSString *fullText = @"If you encounter any problems with the recharge, please click Feedback";
  17. NSString *feedbackText = @"Feedback";
  18. // 方法1:使用原有的一体化方法(向后兼容)
  19. UILabel *feedbackLabel1 = [MOBaseLevelView createFeedbackLabelWithText:fullText
  20. feedbackText:feedbackText
  21. target:self
  22. action:@selector(feedbackButtonClicked)];
  23. feedbackLabel1.frame = CGRectMake(20, 100, self.view.frame.size.width - 40, 50);
  24. [self.view addSubview:feedbackLabel1];
  25. // 方法2:使用新的分离方法 - 更灵活的控制
  26. UILabel *feedbackLabel2 = [[UILabel alloc] init];
  27. feedbackLabel2.numberOfLines = 0;
  28. feedbackLabel2.frame = CGRectMake(20, 180, self.view.frame.size.width - 40, 50);
  29. // 只设置样式,不添加点击事件
  30. [MOBaseLevelView setStyledTextForLabel:feedbackLabel2
  31. fullText:fullText
  32. targetText:feedbackText
  33. color:[UIColor redColor] // 使用红色
  34. hasUnderline:NO]; // 不要下划线
  35. [self.view addSubview:feedbackLabel2];
  36. // 方法3:分别设置样式和点击事件
  37. UILabel *feedbackLabel3 = [[UILabel alloc] init];
  38. feedbackLabel3.numberOfLines = 0;
  39. feedbackLabel3.frame = CGRectMake(20, 260, self.view.frame.size.width - 40, 50);
  40. // 设置绿色下划线样式
  41. [MOBaseLevelView setStyledTextForLabel:feedbackLabel3
  42. fullText:fullText
  43. targetText:feedbackText
  44. color:[UIColor greenColor]
  45. hasUnderline:YES];
  46. // 单独添加点击事件
  47. [MOBaseLevelView addTapGestureToLabel:feedbackLabel3
  48. target:self
  49. action:@selector(customFeedbackAction)];
  50. [self.view addSubview:feedbackLabel3];
  51. // 方法4:多个不同样式的文本
  52. UILabel *multiStyleLabel = [[UILabel alloc] init];
  53. multiStyleLabel.numberOfLines = 0;
  54. multiStyleLabel.frame = CGRectMake(20, 340, self.view.frame.size.width - 40, 80);
  55. NSString *multiText = @"Contact us via Email or call Support hotline";
  56. // 先设置Email样式
  57. [MOBaseLevelView setStyledTextForLabel:multiStyleLabel
  58. fullText:multiText
  59. targetText:@"Email"
  60. color:[UIColor blueColor]
  61. hasUnderline:YES];
  62. // 再设置Support样式(会保留之前的样式)
  63. [MOBaseLevelView setStyledTextForLabel:multiStyleLabel
  64. fullText:multiText
  65. targetText:@"Support"
  66. color:[UIColor purpleColor]
  67. hasUnderline:NO];
  68. [self.view addSubview:multiStyleLabel];
  69. }
  70. #pragma mark - Action Methods
  71. - (void)feedbackButtonClicked {
  72. NSLog(@"Feedback按钮被点击了!");
  73. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"反馈"
  74. message:@"感谢您的反馈!"
  75. preferredStyle:UIAlertControllerStyleAlert];
  76. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定"
  77. style:UIAlertActionStyleDefault
  78. handler:nil];
  79. [alert addAction:okAction];
  80. [self presentViewController:alert animated:YES completion:nil];
  81. }
  82. - (void)customFeedbackAction {
  83. NSLog(@"自定义反馈按钮被点击了!");
  84. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"自定义反馈"
  85. message:@"这是一个自定义的反馈响应!"
  86. preferredStyle:UIAlertControllerStyleAlert];
  87. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"好的"
  88. style:UIAlertActionStyleDefault
  89. handler:nil];
  90. [alert addAction:okAction];
  91. [self presentViewController:alert animated:YES completion:nil];
  92. }
  93. @end