IOS Uiwenview Adjust page font size

Source: Internet
Author: User
Tags uikit

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.