Achieve the effect of image surround text in IOS

Source: Internet
Author: User

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];

Related Article

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.