1.首先创建导航栏按钮
UIBarButtonItem* itemone = [[UIBarButtonItemalloc]initWithImage:[UIImageimageNamed:@"字体加大-1"]style:UIBarButtonItemStyleDonetarget:selfaction:@selector(addLarge)];
UIBarButtonItem* itemtwo = [[UIBarButtonItemalloc]initWithImage:[UIImageimageNamed:@"字体减小-1"]style:UIBarButtonItemStyleDonetarget:selfaction:@selector(addmix)];
self.navigationItem.rightBarButtonItems=@[itemone,itemtwo];
self.navigationItem.rightBarButtonItem.tintColor= [UIColorwhiteColor];
2.创建局部变量(分别是控制大小的变量,和通过接口获取的内容)
@property(nonatomic,assign)int number;
@property(nonatomic,copy)NSString* coment;
3.初始化number =100
_number=100;
4.对coment赋值
_coment=[NSStringstringWithFormat:@"%@",result[@"result"][@"content"]]; 这里是从接口获取标签的内容。展示在webview上。
5.点击增加 和减小的方法
- (void)addLarge {
if(_number<150)
{
_number+=10;
[self.webViewloadHTMLString:_comentbaseURL:nil];
}}
-(void)addmix
{
if(_number>60)
{
_number-=10;
[self.webViewloadHTMLString:_comentbaseURL:nil];
}}
6.最后一步啦(再加载结束后,对webview的字体改变)
- (void)webViewDidFinishLoad:(UIWebView*)webView {
NSString* stre = [NSString stringWithFormat:@"%d",_number];
stre = [stre stringByAppendingFormat:@"%@",@"%"];;
NSString* str = [NSString stringWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%@'",stre];
[UIApplicationsharedApplication].networkActivityIndicatorVisible=NO;
[self.webViewstringByEvaluatingJavaScriptFromString:str];
}