// // FeedbackExample.m // MiMoLive // // 使用示例:如何创建带有蓝色下划线的Feedback文本 // #import "MOBaseLevelView.h" @interface FeedbackExample : UIViewController @end @implementation FeedbackExample - (void)viewDidLoad { [super viewDidLoad]; [self setupExampleLabels]; } - (void)setupExampleLabels { NSString *fullText = @"If you encounter any problems with the recharge, please click Feedback"; NSString *feedbackText = @"Feedback"; // 方法1:使用原有的一体化方法(向后兼容) UILabel *feedbackLabel1 = [MOBaseLevelView createFeedbackLabelWithText:fullText feedbackText:feedbackText target:self action:@selector(feedbackButtonClicked)]; feedbackLabel1.frame = CGRectMake(20, 100, self.view.frame.size.width - 40, 50); [self.view addSubview:feedbackLabel1]; // 方法2:使用新的分离方法 - 更灵活的控制 UILabel *feedbackLabel2 = [[UILabel alloc] init]; feedbackLabel2.numberOfLines = 0; feedbackLabel2.frame = CGRectMake(20, 180, self.view.frame.size.width - 40, 50); // 只设置样式,不添加点击事件 [MOBaseLevelView setStyledTextForLabel:feedbackLabel2 fullText:fullText targetText:feedbackText color:[UIColor redColor] // 使用红色 hasUnderline:NO]; // 不要下划线 [self.view addSubview:feedbackLabel2]; // 方法3:分别设置样式和点击事件 UILabel *feedbackLabel3 = [[UILabel alloc] init]; feedbackLabel3.numberOfLines = 0; feedbackLabel3.frame = CGRectMake(20, 260, self.view.frame.size.width - 40, 50); // 设置绿色下划线样式 [MOBaseLevelView setStyledTextForLabel:feedbackLabel3 fullText:fullText targetText:feedbackText color:[UIColor greenColor] hasUnderline:YES]; // 单独添加点击事件 [MOBaseLevelView addTapGestureToLabel:feedbackLabel3 target:self action:@selector(customFeedbackAction)]; [self.view addSubview:feedbackLabel3]; // 方法4:多个不同样式的文本 UILabel *multiStyleLabel = [[UILabel alloc] init]; multiStyleLabel.numberOfLines = 0; multiStyleLabel.frame = CGRectMake(20, 340, self.view.frame.size.width - 40, 80); NSString *multiText = @"Contact us via Email or call Support hotline"; // 先设置Email样式 [MOBaseLevelView setStyledTextForLabel:multiStyleLabel fullText:multiText targetText:@"Email" color:[UIColor blueColor] hasUnderline:YES]; // 再设置Support样式(会保留之前的样式) [MOBaseLevelView setStyledTextForLabel:multiStyleLabel fullText:multiText targetText:@"Support" color:[UIColor purpleColor] hasUnderline:NO]; [self.view addSubview:multiStyleLabel]; } #pragma mark - Action Methods - (void)feedbackButtonClicked { NSLog(@"Feedback按钮被点击了!"); UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"反馈" message:@"感谢您的反馈!" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]; [alert addAction:okAction]; [self presentViewController:alert animated:YES completion:nil]; } - (void)customFeedbackAction { NSLog(@"自定义反馈按钮被点击了!"); UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"自定义反馈" message:@"这是一个自定义的反馈响应!" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:nil]; [alert addAction:okAction]; [self presentViewController:alert animated:YES completion:nil]; } @end