现在的位置: 主页 > 企业简介 > 文章列表

IOS UIWenView 调整页面字体大小

作者:上海瑞梁浩行投资咨询有限公司 来源:www.60899055.com 发布时间:2017-09-09 10:29:39
 

IOS UIWenView 调整页面字体大小 IOS UIWenView 调整页面字体大小

IOS UIWenView 调整页面字体大小,示例如下:

FontSizeChangeViewController.h #import @interface FontSizeChangeViewController : UIViewController{ UIToolbar *toolBar; } @property (weak, nonatomic) IBOutlet UIWebView *webDetails; @end
FontSizeChangeViewController.m #import FontSizeChangeViewController.h #define K_FONT_SIZE_CHANGE_WEB_URL @ #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 that can be recreated. } #pragma mark - Custom method - (void) initView{ //[S]加载网页 NSURL *url = [[NSURL alloc] initWithString:K_FONT_SIZE_CHANGE_WEB_URL]; // 自适应网页大小,支持放大缩小 self.webDetails.scalesPageToFit = YES; [self.webDetails loadRequest:[NSURLRequest requestWithURL:url]]; //[E]加载网页 //[S]设置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)]; //字体放大按钮 UIBarButtonItem *barBtnAdd = [[UIBarButtonItem alloc] initWithTitle:@字号+ style:UIBarButtonItemStylePlain target:self action:@selector(btnFontSizeChange:)]; barBtnAdd.tag = 1; //字体缩小按钮 UIBarButtonItem *barBtnSmall = [[UIBarButtonItem alloc] initWithTitle:@字号- 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]设置toolbar } //字体大小改变 -(void) btnFontSizeChange:(UIBarButtonItem *)sender{ NSInteger fontSize = [[NSUserDefaults standardUserDefaults] integerForKey:K_FONT_SIZE_CHANGE_KEY]; if (!fontSize){ //默认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:@字号+]) fontSize += 2; else if(sender && [sender.title isEqualToString:@字号-]) fontSize -= 2; strFontSize = [NSString stringWithFormat:@document.body.style.fontSize = '%lDpx';,(long)fontSize]; [self.webDetails stringByEvaluatingJavaScriptFromString:strFontSize]; //更新值 [[NSUserDefaults standardUserDefaults] setInteger:fontSize forKey:K_FONT_SIZE_CHANGE_KEY]; } @end

\

企业建站2800元起,携手武汉肥猫科技,做一个有见地的颜值派!更多优惠请戳:黄冈SEO http://huanggang.raoyu.net

  • 上一篇:Android ORM系列之GreenDao关联关系映射
  • 下一篇:最后一页
  •