webview返回按钮 iOS
来源:互联网 发布:残疾人产品设计 知乎 编辑:程序博客网 时间:2024/05/02 02:27
//
// myWebViewController.m
// webView
//
// Created by wusiping on 15/11/22.
// Copyright (c) 2015年 wusiping. All rights reserved.
//
#import "myWebViewController.h"
@interface myWebViewController ()
@property(nonatomic,weak) UIWebView *myWeb;
@property(nonatomic,weak) UIToolbar *myToolBar;
@property(nonatomic,copy) NSString *currentUrl;
@end
@implementation myWebViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
[selfsetWebView];
[selfaddReturnTool];
[self request];
}
- (void)request
{
//定好url
NSURL *url = [NSURLURLWithString:@"http://m.baidu.com"];
//创建请求
NSURLRequest *request = [NSURLRequestrequestWithURL:url];
//发送请求给服务器
[self.myWebloadRequest:request];
}
- (void)addReturnTool
{
UIToolbar *toolBar = [[UIToolbaralloc]init];
CGFloat toolBarX = 0;
CGFloat toolBarY = 20;
CGFloat toolBarW = [UIScreenmainScreen].bounds.size.width;
CGFloat toolBarH = 50;
CGRect toolBarFrame = CGRectMake(toolBarX, toolBarY, toolBarW, toolBarH);
toolBar.frame = toolBarFrame;
[toolBar setBackgroundColor:[UIColorwhiteColor]];
//给toolbar添加按钮
UIButton *leftButton = [[UIButtonalloc]init];
CGFloat leftButtonX = 25;
CGFloat leftButtonY = 5;
CGFloat leftButtonW = 50;
CGFloat leftButtonH = 30;
CGRect leftButtonFrame = CGRectMake(leftButtonX, leftButtonY, leftButtonW, leftButtonH);
leftButton.frame = leftButtonFrame;
[leftButton setTitle:@"返回"forState:UIControlStateNormal];
[leftButton setBackgroundColor:[UIColorgrayColor]];
//leftButton添加点击操作
[leftButton addTarget:selfaction:@selector(goBack)forControlEvents:UIControlEventTouchUpInside];
[toolBar addSubview:leftButton];
_myToolBar = toolBar;
[self.viewaddSubview:_myToolBar];
}
- (void)goBack
{
// 判断是否可以返回,如果可以,就返回
if (_myWeb.canGoBack) {
_currentUrl =_myWeb.request.URL.absoluteString;
NSLog(@"%@",_currentUrl);
//判断当前url是否== 某个连接,如果等于就执行某个操作(比如直接返回主页)
if ([_myWeb.request.URL.absoluteString isEqual: @"http://m.baidu.com"]) {
//返回主页相关代码
}
[_myWeb goBack];
}
}
- (void)setWebView
{
UIWebView * myWeb = [[UIWebViewalloc]init];
CGFloat webX = 0;
CGFloat webY = 70;
CGFloat webW = [UIScreenmainScreen].bounds.size.width;
CGFloat webH = [UIScreenmainScreen].bounds.size.height -49;
CGRect webFrame = CGRectMake(webX, webY, webW, webH);
myWeb.frame = webFrame;
_myWeb = myWeb;
[self.viewaddSubview:_myWeb];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
- webview返回按钮 iOS
- webView 返回按钮和关闭按钮
- iOS自定义返回按钮
- ios返回按钮
- iOS之返回按钮
- IOS UINavigationBar 自定义返回按钮
- IOS 自定义UINavigationBar返回按钮
- iOS导航栏返回按钮
- ios UINavigationController 修改返回按钮
- IOS隐藏navigationItem返回按钮与自定义返回按钮
- ios Webview上返回上一个网页
- iOS 开发 webView返回上一页
- Android之WebView后退按钮为返回上一个页面
- ios NavigationController里面默认得返回按钮
- IOS中导航的返回按钮定制
- iOS 更改导航栏返回按钮文字
- iOS自定义导航栏的返回按钮
- iOS导航栏返回按钮(全局)
- HDU1029-Ignatius and the Princess IV
- 在ubuntu下安装python imagine library
- 如何使用富文本编辑器xheditor
- 【poj2575】Jolly Jumpers
- Extjs5 常用layout
- webview返回按钮 iOS
- 控制反转IOC(依赖注入DI),注入类型,自动装配相关注解
- getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir()的作用,getfilesdir
- 动态设置RelativeLayout布局
- EMC的一道数字编程编程题
- secureCRT sftp 使用
- ios9网络请求https适配
- POJ3580 SuperMemo(Splay的区间操作)
- standalone在XML里的作用