iOS native 控制 uiwebview 字体的大小
2013-10-20 21:13
344 查看
我们可以通过ios native 控制webview的字体大小,以前总觉得不可以,原来这样也是可以的,代码如下新建一个工程,
然后在ViewController.m文件中复制下面代码:
上面我们是用新浪首页做了试验。效果如下:
效果二:
然后在ViewController.m文件中复制下面代码:
@interface ViewController()<UIWebViewDelegate> { UIActivityIndicatorView* activityIndicator; UIWebView* _webView; UISlider* Slide; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // self.view.backgroundColor = [UIColor blackColor]; Slide = [[UISlider alloc] initWithFrame:CGRectMake(50, 10, 1000, 20)]; [Slide addTarget:self action:@selector(SlideChange) forControlEvents:UIControlEventValueChanged]; Slide.maximumValue = 1000.0f; Slide.minimumValue =10.0f; Slide.value = 10.0f; [self.view addSubview:Slide]; _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,40,1024, 728)]; _webView.delegate = self; [self.view addSubview:_webView]; NSURL* url = [NSURL URLWithString:@"http://www.sina.com"]; NSURLRequest* request = [[NSURLRequest alloc] initWithURL:url]; [_webView loadRequest:request]; activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 40, 50)]; activityIndicator.center = self.view.center; activityIndicator.backgroundColor = [UIColor grayColor]; [activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite]; [activityIndicator startAnimating]; [self.view addSubview:activityIndicator]; } - (void)webViewDidStartLoad:(UIWebView *)webView { } - (void)webViewDidFinishLoad:(UIWebView *)webView { [activityIndicator stopAnimating]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)SlideChange { NSString* str1 =[NSString stringWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%f%%'",Slide.value]; [_webView stringByEvaluatingJavaScriptFromString:str1]; }
上面我们是用新浪首页做了试验。效果如下:
效果二:
相关文章推荐
- IOS UIWebView的字体大小控制
- [ios] UIWebView字体控制
- IOS开发之改变UIWebView文本字体的样式和大小
- UIWebView 控制页面 字体 大小
- IOS_UIWebView字体大小、字体颜色、背景色
- IOS-UIWebView字体控制
- IOS_UIWebView字体大小、字体颜色、背景色
- IOS开发之改变UIWebView文本字体的样式和大小
- ios开发之改变UIWebView文本字体的样式和大小
- IOS_UIWebView字体大小、字体颜色、背景色
- iOS:使用minimumScaleFactor控制字体大小自适应
- ios开发之改变UIWebView文本字体的样式和大小
- iOS_UIWebView字体大小、字体颜色、背景色
- IOS_UIWebView字体大小、字体颜色、背景色
- iOS:使用minimumScaleFactor控制字体大小自适应
- IOS-UIWebView字体控制
- [ios] UIWebView字体控制
- iOS 设置UIWebView 展示字体大小,颜色,展示布局
- ios 动态修改UILabel字体大小
- iOSWebview与js交互之调整字体大小