UIWebView加上safari风格前进后退按钮(转)
2016-04-28 09:02
337 查看
今天在写程序内打开网页的功能,写工具条的时候发现系统图标里面竟然没有后退按钮,,由于我这个是静态库工程,不可能自己弄张图上去,不然使用本库的时候还得附上图片,经过一下午的搜索,终于找到个比较靠谱的,这哥们硬是用代码给画出来个箭头了(话说如果是其他不规则的图形要咋办呢?),还是google管用啊,baidu非常非常非常。。。垃圾。
Recently, I had need to provide a back button similar to the one used in Mobile Safari for a consulting project.
Many of the buttons used in the built-in iPhone applications are made available via the SDK with built in button types and graphics. Unfortunately, the back button is not one of these.
Because I needed to display the toolbar button from inside a static library which can not include images, I had to render the back arrow directly in code.
Since this was a bit time consuming, I thought I would share in hopes that it saves someone else a little bit of time.
Code Example: Drawing the iPhone Back Button(转载)
Recently, I had need to provide a back button similar to the one used in Mobile Safari for a consulting project.
Many of the buttons used in the built-in iPhone applications are made available via the SDK with built in button types and graphics. Unfortunately, the back button is not one of these.
Because I needed to display the toolbar button from inside a static library which can not include images, I had to render the back arrow directly in code.
Since this was a bit time consuming, I thought I would share in hopes that it saves someone else a little bit of time.
- (CGContextRef)createContext { // create the bitmap context CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef context = CGBitmapContextCreate(nil,27,27,8,0, colorSpace,kCGImageAlphaPremultipliedLast); CFRelease(colorSpace); return context; } - (CGImageRef)createBackArrowImageRef { CGContextRef context = [self createContext]; // set the fill color CGColorRef fillColor = [[UIColor blackColor] CGColor]; CGContextSetFillColor(context, CGColorGetComponents(fillColor)); CGContextBeginPath(context); CGContextMoveToPoint(context, 8.0f, 13.0f); CGContextAddLineToPoint(context, 24.0f, 4.0f); CGContextAddLineToPoint(context, 24.0f, 22.0f); CGContextClosePath(context); CGContextFillPath(context); // convert the context into a CGImageRef CGImageRef image = CGBitmapContextCreateImage(context); CGContextRelease(context); return image; } - (UIBarButtonItem *)backButton { CGImageRef theCGImage = [self createBackArrowImageRef]; UIImage *backImage = [[UIImage alloc] initWithCGImage:theCGImage]; CGImageRelease(theCGImage); UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:backImage style:UIBarButtonItemStylePlain target:self.webView action:@selector(goBack)]; [backImage release], backImage = nil; return [backButton autorelease]; }
相关文章推荐
- Android Frame Animation 实现图片刷新等待过程
- 微信看呆!阿里钉钉宣布推出多人视频会议:免费高清
- 关于图片转化为NSDATA
- ios goto语法。
- iOS开发之手势识别
- Android-SharedPreferences保存登录数据
- iOS 上架提示ipad需要显示四个方位,而我们只能竖屏的时候的解决办法
- Android Studio教程从入门到精通
- Web移动端Fixed布局的解决方案
- ios7设计思想(界面坐标上移的原因)
- Android : The import java.util cannot be resolved
- android轻量级缓存框架ASimpleCache分析
- iOS开发: iOS蓝牙4.0开发例子
- Android SharedPreferences的数据存储
- Android-AlertDialog各种对话框的用法
- [C语言][LeetCode][448]Find All Numbers Disappeared in an Array
- 【Unity3d开发记录】Unity动态画曲线、弧线(GL画线)在UI上的显示
- Android杂记(3)关于Uri转化为File
- [修复] Firemonkey 画线问题(Android & iOS 平台)
- xUtils AndroidStudio安装