ibireme / YYText

Powerful text framework for iOS to display and edit rich text.
MIT License
8.86k stars 1.7k forks source link

网络请求的字符串中含有\n无法识别 #660

Open AbnerPei opened 7 years ago

AbnerPei commented 7 years ago
  _messLB = [YYLabel new];
    _messLB.backgroundColor = [UIColor brownColor];
    _messLB.frame = CGRectMake(50, 260, 240, 200);
    _messLB.numberOfLines = 0;
    _messLB.textColor = [UIColor purpleColor];
    [self.view addSubview:_messLB];

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:@10 forKey:@"type"];
    [param setValue:@"{}" forKey:@"gson"];
    [manager POST:@"http://hao.oudot.cn/tongji_app/JsonManageServlet?" parameters:param progress:^(NSProgress * _Nonnull uploadProgress) {

    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

        NSDictionary *resultDict = (NSDictionary *)responseObject;
        NSDictionary *retBodyDict = [resultDict objectForKey:@"retBody"];
        NSArray *businessListArr = [retBodyDict objectForKey:@"businessList"];
        NSDictionary *messDict = businessListArr[0];
        NSString *infoStr = [messDict objectForKey:@"businessInfo"];

        NSLog(@"infoStr is --- %@",infoStr);

#warning 把请求的数据放到这里,就可以实现换行,why??
#warning 把请求的数据放到这里,就可以实现换行,why??
#warning 把请求的数据放到这里,就可以实现换行,why??

        //        infoStr = @"我应该是一个详情。我应该\n\n是一个详情。我应该是一个详情。我应该是一个详情。我应该是一个详情。我应该是一个详情。我应该是一个详情。我应该是一个详情。我应该是一个详情。我应该是一个详情。我应该是一\n\n个详情。我应该是一个详情。";
        NSMutableAttributedString *mutStr = [[NSMutableAttributedString alloc]initWithString:infoStr];
        _messLB.attributedText = mutStr;
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

    }];
baileilei commented 6 years ago

我也遇到了相同的问题, 附上图片。 本应该是左图,但是用了YYLabel之后显示少了一行换行。/var/folders/96/b6khv7x12vl8p1mvw2yjzg2m0000gn/T/com.evernote.Evernote/com.evernote.Evernote/WebKitDnD.GVrUAe/151513041255.pic.jpg 12b31cd4-eb15-4ddb-8d38-ef4bb6428daa ![151513041255 pic](https://user-images.githubusercontent.com/11979415/33862887-f8ccb6f0-df1f-11e7-8a44-b7485c9bc5a4.jpg)