IOS Uiwenview Adjust page font size
IOS uiwenview Adjust the page font size, as shown in the following example:
FontSizeChangeViewController.h
#import <UIKit/UIKit.h> @interface fontsizechangeviewcontroller:uiviewcontroller{ uitoolbar *toolbar;} @property (Weak, nonatomic) Iboutlet UIWebView *webdetails; @end
Fontsizechangeviewcontroller.m
#import "FontSizeChangeViewController.h" #define K_font_size_change_web_url @ "http://3g.fx678.com/news/detail/ 201508031037021902 "#define K_font_size_change_key @" Ont_size_change_view_size "@interface Fontsizechangeviewcontroller () @end @implementation fontsizechangeviewcontroller-(void) Viewdidload {[Super Viewdidload]; [Self initview];} -(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} #pragma mark-custom method-(void) initview{//[s] Load Web page nsurl *url = [[Nsurl alloc] Initwithstring:k_font_size_chan Ge_web_url]; Adaptive page size, support zoom self.webDetails.scalesPageToFit = YES; [Self.webdetails loadrequest:[nsurlrequest Requestwithurl:url]; [E] Load page//[s] Set toolbar cgsize cgsize = self.navigationController.toolbar.frame.size; if (!toolbar) ToolBar = [[Uitoolbar alloc] Initwithframe:cgrectmake (0, Self.view.frame.size.height-cgsize.height, Cgsize.width, Cgsize.height)]; Font Magnification buttonUibarbuttonitem *barbtnadd = [[Uibarbuttonitem alloc] initwithtitle:@ "Font size +" Style:uibarbuttonitemstyleplain target: Self action: @selector (Btnfontsizechange:)]; Barbtnadd.tag = 1; Font Zoom Out button Uibarbuttonitem *barbtnsmall = [[Uibarbuttonitem alloc] initwithtitle:@ "Font Size-" style:uibarbuttonitemstyleplain Target:self Action: @selector (Btnfontsizechange:)]; Barbtnadd.tag = 2; Nsarray *arrbtns = [Nsarray arraywithobjects:barbtnadd,barbtnsmall, Nil]; [ToolBar Setbarstyle:uibarstyledefault]; Toolbar.autoresizingmask = Uiviewautoresizingflexibletopmargin; [ToolBar Setitems:arrbtns Animated:yes]; [Self.view Addsubview:toolbar]; [E] Set toolbar}//font size change-(void) Btnfontsizechange: (Uibarbuttonitem *) sender{Nsinteger fontSize = [[Nsuserdefaults] Standarduserdefaults] Integerforkey:k_font_size_change_key]; if (!fontsize) {//default 18px [[Nsuserdefaults standarduserdefaults] setinteger:18 Forkey:k_font_size_change_key] ; FontSize = [[Nsuserdefaults standarduserDefaults] Integerforkey:k_font_size_change_key]; } nsstring *strfontsize = nil; if (sender && [sender.title isequaltostring:@ "size +"]) fontSize + = 2; else if (sender && [sender.title isequaltostring:@ "Font Size-"]) fontSize-= 2; Strfontsize = [NSString stringwithformat:@ "document.body.style.fontSize = '%ldpx ';", (long) fontSize]; [Self.webdetails stringbyevaluatingjavascriptfromstring:strfontsize]; Update value [[Nsuserdefaults standarduserdefaults] setinteger:fontsize Forkey:k_font_size_change_key];} @end
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
IOS Uiwenview Adjust page font size