iOS Navigationcontroller slide back with webview load HTML picture Adaptive screen width

Source: Internet
Author: User

1. iOS Navigationcontroller sliding back

Sliding back is the function of the Navigationcontroller default return button, if the Back button is customized, the function fails,

There are two ways to solve this problem:

Self . Navigationitem . Backbarbuttonitem = [[uibarbuttonitemalloc]initwithcustomview: button];//This method doesn't work .

can only be used

Self . Navigationitem . Backbarbuttonitem =

[[Uibarbuttonitem Alloc]initwithtitle:style:target:action:]

The selection range is small,

Ii

UIButton*button = [UIButtonbuttonwithtype: uibuttontypecustom];

[button setframe:cgrectmake(0,0, (Max.)];

[button settitle:@ " return " Forstate:uicontrolstatehighlighted];

[button settitle:@ " back "forstate: uicontrolstatenormal];

[button addTarget:selfAction: @selector(back)forcontrolevents:uicontroleventtouchupinside ];

uibarbuttonitem*bar = [[uibarbuttonitemalloc] Initwithcustomview: button];

self. Navigationitem . Leftbarbuttonitem = bar;

But after the push, add

if ([self. Navigationcontroller respondstoselector:@selector(Interactivepopgesturerecognizer)]) {

self. Navigationcontroller . Interactivepopgesturerecognizer . Delegate = Nil ;

}

2. WebView Loading HTML Image Adaptive screen width


When you load HTML with WebView, if you have a picture in the HTML, if you do not deal with HTML, you will find that the loaded pictures are some of the

The screen does not fit itself, there are two ways to deal with it at this time,

① to WebView to do the next treatment,

self. Mwebview . Scalespagetofit = YES ;

This method is not perfect, the picture will fit the screen, but the font will become smaller,

② write an extended class of WebView

Inside the HTML text with JS or CSS to do a bit of processing, add a head


[data_content appendString:@ "];

[data_content appendString:@ "];

[content appendString:@ "<meta charset=\" utf-8\ ">"];

[content appendString:@ "<meta id=\" viewport\ "name=\" viewport\ "content=\ "Width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=false\"/>"];

[content appendString:@ "<meta name=\" apple-mobile-web-app-capable\ "content=\" Yes\ "/>"];

[content appendString:@ "<meta name=\" apple-mobile-web-app-status-bar-style\ " Content=\ "Black\"/>"];

[content appendString:@ "<meta name=\" black\ "name=\" Apple-mobile-web-app-status-bar-style\ "/>"];

[content appendString:@ "<style>img{width:100%;} </style> "];

[content appendString:@ "<style>table{width:100%;} </style> "];

[content appendString:@ "<title>webview</title>"];

This processing is perfect, can also be added to the end of the HTML, but not placed in the head of flexible,

iOS Navigationcontroller slide back with webview load HTML picture Adaptive screen width

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.