目前,不少在线教育平台中,为了验证课堂的教学效果或学员学习状况,通常都内置了做业系统。学员在上传做业的过程当中,有可能会上传多张图片并按序(自下而上)排列,那么这个功能是如何实现的呢?下面小编就以iOS版本的在线教育平台开发为例,来讲明下,如何使用WKWebView来实现图片排列。
1、先建立一个wkwebviewcss
- (WKWebView *)wkWebV{ if (!_wkWebV) { _wkWebV = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height)]; } return _wkWebV; }
2、建立一个获取图片数组html
- (void)getImageData{ //图片连接数组,这里随便找了几张图片 NSArray *array = @[@“https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1688444226,912774195&fm=26&gp=0.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1597380686451&di=9c0c95578967f990f80df47815f75403&imgtype=0&src=http%3A%2F%2F01.minipic.eastday.com%2F20161212%2F20161212144027_cded4c83f17c47604eb2be0530bb43ba_7.jpeg"]; NSString *htmlStr = @“"; //遍历图片数组,添加img标签 for (NSString *str in array) { NSString *ssss = [NSString stringWithFormat:@"<img src='%@'></img>",str]; htmlStr = [NSString stringWithFormat:@"%@%@",htmlStr,ssss]; } //设置CSS NSString * htmlStyle = @" <style type=\"text/css\"> *{min-width: 100% !important;max-width: 100% !important;} img{ height: auto !important;} </style> “; //把CSS和img标签拼接 htmlStr = [htmlStyle stringByAppendingString:htmlStr]; //使用WKWebview加载HTMLSting [_wkWebV loadHTMLString:htmlStr baseURL:nil]; }
以上就是在线教育平台开发中,如何使用WKWebView来实现做业功能中的图片排列效果。web