IOS UIWenView adjust page font size

Source: Internet
Author: User

IOS UIWenView adjust page font size
IOS UIWenView adjust page font size

IOS UIWenView:

 

FontSizeChangeViewController. h

 

#import 
 
  @interface FontSizeChangeViewController : UIViewController{    UIToolbar *toolBar;}@property (weak, nonatomic) IBOutlet UIWebView *webDetails;@end
 

 

FontSizeChangeViewController. m
# Import FontSizeChangeViewController. h # define repository @ http://3g.fx678.com/news/detail/201508031037021902#define repository @ login @ interface FontSizeChangeViewController () @ end @ implementation FontSizeChangeViewController-(void) viewDidLoad {[super viewDidLoad]; [self initView];}-(void) didReceiveMemoryWarning {[super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated .} # pragma mark-Custom method-(void) initView {// [S] load webpage NSURL * url = [[NSURL alloc] initWithString: K_FONT_SIZE_CHANGE_WEB_URL]; // adaptive webpage size, allows you to zoom in and out self. webDetails. scalesPageToFit = YES; [self. webDetails loadRequest: [NSURLRequest requestWithURL: url]; // [E] loading a webpage // [S] sets 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 extension button UIBarButtonItem * barBtnAdd = [[UIBarButtonItem alloc] initWithTitle: @ font size + style: Custom target: self action: @ selector (btnFontSizeChange :)]; barBtnAdd. tag = 1; // The UIBarButtonItem * barBtnSmall = [[UIBarButtonItem alloc] initWithTit Le: @ 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] sets toolbar} // Changes the font size-(void) btnFont SizeChange :( UIBarButtonItem *) sender {NSInteger fontSize = [[NSUserDefaults standardUserDefaults] integerForKey: K_FONT_SIZE_CHANGE_KEY]; if (! FontSize) {// default 18px [[NSUserDefaults standardUserDefaults] setInteger: 18 forKey: Keys]; fontSize = [[NSUserDefaults standardUserDefaults] integerForKey: Keys];} NSString * strFontSize = nil; if (sender & [sender. title isEqualToString: @ font 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 the value [[NSUserDefaults standardUserDefaults] setInteger: fontSize forKey: K_FONT_SIZE_CHANGE_KEY];} @ end


 

 

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.