IOS UIWenView 調整頁面字型大小

來源:互聯網
上載者:User

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 @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 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


 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.