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