In iOS, it is sometimes necessary to achieve the effect of text wrapping images, which is difficult to achieve with a general control, because the control does not support this attribute at all. The compromise is to use uiwebview, the HTML language is loaded to achieve the effect of text wrapping.
Implementation requirements: Enable text-enclosed images on webview, and click images to enlarge the image.
There are two ways to enlarge the Click image: 1. Use a Javascript script, but I have not performed web development for three years. This method may take a long time. 2. Add a bitmap (must be transparent) to webview.
Add uiimageview and click the corresponding position on Web. scrollview.
The following code is used:
Newstitle = @ "title ";
Newstime = [nsstring stringwithformat: @ "% @", @ "2012-08-09", @ "Netease"];
Nsstring * file1 = [[nsbundle mainbundle] pathforresource: @ "occupied bitmap" oftype: @ "PNG"]; // sets the placeholder Image
Nsstring * file2 = [[nsbundle mainbundle] pathforresource: @ "Transparent" oftype: @ "PNG"]; // sets the placeholder Image
Nsstring * imgstr = [nsstring stringwithformat: @ "10px, 10 Px to the right
Web. backgroundcolor = [uicolor clearcolor];
Web. opaque = no;
// This line can speed up loadhtmlstring under the simulator
In fact, the loading process cannot be felt even if there is no sentence on the real machine.
Web. datadetectortypes = uidatadetectortypenone;
If (! News ){
News = @ "the text to be added the text to be added the text to be added text to be added the text to be added ";
}
Nsstring * webviewtext = [nsstring stringwithformat: @ "<style> body {margin: 10; align: center; Background-color: lightgray; font-color: black; Font: 17px/20px
Custom-font-name }</style> <H2 align = \ "center \" >%@ </H2> <H5 style = 'text-align: center; '>%@ </H5> <HR> </BR >%@ <font >%@ </font> ", newstitle, newstime, imgstr, news]; // The red part links the text image together.
[Web loadhtmlstring: webviewtext baseurl: Nil]; // In webview
Display local strings
// Add the same image as the bitmap
Uiview * firstview = [self addimageviewwithframe: cgrectmake (203,125,100, 97) andpic: pic1];
[Firstview settag: 9];
[Web. scrollview addsubview: firstview];
[Web. scrollview addsubview: [self addimageviewwithframe: cgrectmake (203,226,100, 97) andpic: pic2];