//
// MYViewController.m
// YYTextDemo
//
// Created by 刘小二 on 16/6/13.
// Copyright © 2016年 ibireme. All rights reserved.
//
#import "MYViewController.h"
#import "YYTextView.h"
@interface MYViewController () <YYTextViewDelegate,UIWebViewDelegate>
@property (nonatomic, strong) YYTextView *textView;
@property (nonatomic, strong) UIWebView *webView;
@end
@implementation MYViewController
- (void)loadView {
UIScrollView *scrol = [[UIScrollView alloc] init];
scrol.frame = [UIScreen mainScreen].bounds;
scrol.contentSize = CGSizeMake(375, 10000);
self.view = scrol;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.textView = [[YYTextView alloc] initWithFrame:self.view.bounds];
NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"1.plist" ofType:nil]];
self.textView.text = dic[@"url"];
self.textView.editable = NO;
self.textView.allowsPasteAttributedString = NO ;
self.textView.selectable =NO ;
self.textView.allowsCopyAttributedString = NO;
self.textView.dataDetectorTypes = UIDataDetectorTypeAll;
self.textView.delegate = self;
// [self.view addSubview:self.textView];
self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:self.webView];
self.webView.scrollView.scrollEnabled = NO;
// self.webView.userInteractionEnabled = NO;
NSString * formatString = @"<span style=\"font-size:13px;color:#ffa443\">%@</span>";
NSString *str = [dic[@"url4"] stringByReplacingOccurrencesOfString:@"\n" withString:@"<br>"];
NSString * htmlString = [NSString stringWithFormat:formatString,str];
[self.webView loadHTMLString:htmlString baseURL:nil];
self.webView.delegate = self;
}
- (void)textView:(YYTextView *)textView didTapHighlight:(YYTextHighlight *)highlight inRange:(NSRange)characterRange rect:(CGRect)rect {
// void(^YYTextAction)(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect)
highlight.tapAction = ^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect) {
NSLog(@"%@",[text attributedSubstringFromRange:range].string);
};
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
// NSString *jsString = [[NSString alloc] initWithFormat:@"document.body.style.fontSize=%f;document.body.style.color=%@",15.0,@"ffa443"];
// [webView stringByEvaluatingJavaScriptFromString:jsString];
[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
// Disable callout
[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
NSLog(@"%f",webView.scrollView.contentSize.height);
CGRect frame = webView.frame;
frame.size.height = webView.scrollView.contentSize.height;
webView.frame = frame;
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ([request.URL.absoluteString hasPrefix:@"http"]) {
[[UIApplication sharedApplication]openURL:request.URL];
return false;
}
return true ;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
加载html文本遇到\n不换行的解决办法
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 【蝴蝶效应】 蝴蝶效应:上个世纪70年代,美国一个名叫洛伦兹的气象学家在解释空气系统理论时说,亚马逊雨林一只蝴蝶...