UIWebView plus Safari style forward back button (go)

Source: Internet
Author: User

Today in the writing program to open the function of the Web page, write the toolbar when the System icon found there is no back button, because I this is a static library project, it is not possible to get a picture on their own, or use this library when you have to attach a piece, after an afternoon search, finally found a more reliable, This guy just used the code to draw out an arrow (say if it is other irregular graphics to do?) ), or Google is working ah, Baidu is very very very ... Garbage. Code example:drawing the IPhone back Button (reprint)

Recently, I had need to provide a back button similar to the one used on Mobile Safari for a consulting project.

Many of the buttons used in the built-in IPhone applications is made available via the SDK with built in button types and Graphics. Unfortunately, the back button was not one of the these.

Because I needed to display the toolbar button from inside a static library which can does include images, I had to render The back arrow directly in code.

Since This is 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 contextcgcolorspaceref 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 colorcgcolorref 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 cgimagerefcgimageref 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:backImagestyle:UIBarButtonItemStylePlaintarget : self.webviewaction: @selector (goBack)]; [Backimage release], backimage = Nil;return [Backbutton autorelease];}

UIWebView plus Safari style forward back button (go)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.