<span id="Label3"></p><p><p>today, Bo Master has a picture and text mixed with the demand, encountered some difficulties, here and we share, hope to progress Together.</p></p><p><p>Before iOS7.0, there are two main methods of picture and text Blending: 1.webview+js 2.coreText</p></p><p><p>After iOS7.0, Apple offers a new package that makes it easier to mix text and graphics, which is the third method: 3.TextKit</p></p><p><p>Today and everyone in detail to share the three kinds of picture and text mix method</p></p><p><p>1.webview+js method is actually very simple, the following code, you do your own research</p></p><p><p>Remove WebView when scrolling, up and down white edges.</p></p><pre class="prettyprint cs"><pre class="prettyprint cs">-(<span class="keyword">void) clearwebviewbackground: (uiwebview *) webview{ uiwebview *web = webView; in <span class="keyword"><span class="keyword">Web.subviews) { <span class="keyword"><span class="keyword">class]]) { [v setbounces:no]; </span></span> </span></span> </span> }}}</pre></pre><p><p>Set up Proxy</p></p><pre class="prettyprint php"><pre class="prettyprint php"><span class="comment">Set proxy <span class="keyword">self.mywebview.delegate= self<span class="keyword">;</span> </span></span></pre></pre><p><p>Add a view that loads WebView</p></p><pre class="prettyprint xml">#pragma mark load Webview-(void) loadmywebview{<span class="indent">NSString *[email protected] "han cold" after the "wonderful gold suction 3 cheats";<span class="indent"> <span class="indent">NSString *linkstr=[nsstring stringwithformat:@ "<span class="tag"><<span class="title">A<span class="attribute">href=<span class="value">'%@ ' > My blog<span class="tag"></<span class="title">A><span class="tag"><<span class="title">A<span class="attribute">href=<span class="value">'%@ ' > Original<span class="tag"></<span class="title">a> ", @" http://blog.csdn.net/wildcatlele ", @" http://jincuodao.baijia.baidu.com/article/26059 "];<span class="indent"> <span class="indent">NSString *[email protected] "han Cold after will be endless" the ability to absorb gold I am surprised! The August 12 film box office has successfully breached the 600 million Mark. And the amount of the row is still more than 10, to the daily rate of tens of millions of steady march to 700 Million. ";<span class="indent"> <span class="indent">NSString *[email protected] "you know," after will be "is not the mainstream genre film, is a literary film. Unlike "little times", is a mainstream business idol Movie. ";<span class="indent">NSString *image1=[nsstring stringwithformat:@ "<span class="tag"><<span class="title">Img<span class="attribute">Src=<span class="value">‘%@‘<span class="attribute">height=<span class="value">' 280 '<span class="attribute">Width=<span class="value">'/> ', @ "http://nvren.so/uploads/allimg/c140801/140DR4554L40-YB9.jpg"];<span class="indent">NSString *image2=[nsstring stringwithformat:@ "<span class="tag"><<span class="title">Img<span class="attribute">Src=<span class="value">‘%@‘<span class="attribute">height=<span class="value">' 280 '<span class="attribute">Width=<span class="value">'/> ', @ "http://f.hiphotos.baidu.com/news/w%3D638/sign=78315beeb1fb43161a1f797918a44642/ 2934349b033b5bb58cb61bdb35d3d539b600bcb5.jpg "];<span class="indent"> <span class="indent">NSString *[email protected] "it's so wonderful!" Some people say that this is the Chinese film Market dividend, is the success of fan Movies. however, There is an investment of 30 million of the fan movie "i am me", There are stars, production is also good, basically a fiasco. ";<span class="indent"> <span class="indent">NSString *[email protected] "after will life" sell is not a good story, is a Superiority. Especially for 80, the population, you have not found, see "after will be endless" than see "small times 3" There is a clear sense of Superiority. Although the story is general, but many people after reading, will be on weibo, on the photo. therefore, It is not the breadth but the depth of an ethnic Group.<span class="tag"><<span class="title">Br><span class="indent"> <span class="indent">Very vicious, worthy of reference for EVERYONE. Han Cold "after will be endless" and what secret weapons, welcome "after will be endless" team or related party explosive material, Direct message can be sent Li Vanchang autographed "participation feeling" a Book. ";<span class="indent"> <span class="indent">Initialization and HTML strings<span class="indent">NSString *htmlurlstr=[nsstring stringwithformat:@ "<span class="tag"><<span class="title">Body<span class="attribute">style=<span class="value">‘<span class="tag"><<span class="title">h2>%@<span class="tag"><span class="tag"></<span class="title">h2><span class="tag"><<span class="title">p>%@ <span class="tag"></<span class="title">p> <span class="tag"><<span class="title">p>%@ <span class="tag"></<span class="title">p>%@ <span class="tag"><<span class="title">br> <span class="tag"><<span class="title">p>%@<span class="tag"></<span class="title">p> <span class="tag"><<span class="title">p>%@<span class="tag"></<span class="title">p>%@ <span class="tag"><<span class="title">p>%@<span class="tag"></<span class="title">p> <span class="tag"></<span class="title">body> ", title,linkstr,p1,image1,p2,p3,image2,p4]; <span class="indent"> <span class="indent"> [self.mywebview loadhtmlstring:htmlurlstr baseurl:nil];} </span> </span> </span> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></pre><p><p>Implementing Proxy methods (handling connection Click Events)</p></p><pre class="prettyprint cs">-(BOOL) webView: (uiwebview *) webView shouldstartloadwithrequest: (nsurlrequest *) Request Navigationtype: ( Uiwebviewnavigationtype) navigationtype{<span class="indent">NSString *urlstr=request. url.absolutestring;<span class="indent"> <span class="indent">NSLog (<span class="string">@ "url:%@", urlstr);<span class="indent"> <span class="indent"> <span class="comment">empty, load This page for the first time<span class="indent"> <span class="keyword">If ([urlstr isequaltostring:<span class="string">@ "about:blank"]) {<span class="indent"> <span class="indent"> <span class="keyword">Return YES;<span class="indent">}<span class="indent"> <span class="indent"> <span class="comment">Set the view controller after the click<span class="indent"><span class="indent"> Lvesoriginalcontroller *originalc=[[lvesoriginalcontroller alloc] init]; <span class="indent"> originalc.originurl=urlstr; <span class="comment">//set request Connection <span class="indent"> <span class="comment">//jump to the controller after click and load WebView <span class="indent"> [self.navigationcontroller pushviewcontroller:originalc animated:yes]; <span class="indent"> <span class="indent"> <span class="keyword">return NO; <span class="comment">//setting bottom scrolling does not bounce Back-(<span class="keyword">void) webviewdidfinishload: (uiwebview *) Webview{<span class="indent"> Nsinteger height = [[webView stringbyevaluatingjavascriptfromstring:<span class="string">@ " document.body.offsetHeight; "] intvalue]; <span class="indent"> nsstring* javascript = [nsstring stringwithformat:<span class="string">@ "window.scrollby (0,%d ); ", height]; <span class="indent"> [webView stringbyevaluatingjavascriptfromstring:javascript];} <br> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></pre><p><p>2.coreText is the bottom of the graphic mix, if you want to write your own text layout engine, you can use Coretext</p></p><p><p>-(void) drawrect: (cgrect) Rect {</p></p><p><p>Drawing Code</p></p><p><p>[super drawrect:rect];</p></p><p><p>1. Gets the context of the current drawing canvas for subsequent drawing of the content on the canvas</p></p><p><p>Cgcontextref Context=uigraphicsgetcurrentcontext ();</p></p><p><p>2. Flip the coordinate system up or down. For the underlying drawing engine, the lower-left corner of the screen is (0, 0) coordinates. For the upper UIKit, the upper-left corner is (0, 0) coordinates. So we're going to do the UIKit for the following coordinate system, so we're going to do a top-down rotation of the coordinate system Here. After flipping, the bottom and top (0, 0) coordinates are Coincident.</p></p><p><p>Cgcontextsettextmatrix (context, cgaffinetransformidentity);</p></p><p><p>CGCONTEXTTRANSLATECTM (context, 0, self.bounds.size.height);</p></p><p><p>CGCONTEXTSCALECTM (context, 1.0,-1.0);</p></p><p><p>3.</p></p><p><p>Cgmutablepathref path=cgpathcreatemutable ();</p></p><p><p>Cgpathaddrect (path, NULL, self.bounds);</p></p><p><p>4. Create the area of the drawing, Coretext itself supports a variety of text typesetting area, We here simply to UIView the entire interface as the layout of the area</p></p><p><p>Nsattributedstring *attstring=[[nsattributedstring alloc]initwithstring:@ "Hello world! "];</p></p><p><p>Ctframesetterref framestter=ctframesettercreatewithattributedstring ((cfattributedstringref) attString);</p></p><p><p>Ctframeref frameofct=ctframesettercreateframe (framestter, cfrangemake (0, [attstring length]), path, NULL);</p></p><p><p>5.</p></p><p><p>Ctframedraw (frameofct, context);</p></p><p><p>6.</p></p><p><p>Cfrelease (frameofct);</p></p><p><p>Cfrelease (path);</p></p><p><p>Cfrelease (framestter);</p></p><p><p>}</p></p><p><p>Http://www.cocoachina.com/industry/20140521/8504.html</p></p><p><p>Http://www.tuicool.com/articles/jEBrq2B</p></p><p><p></p></p><p><p>3.TextKit is a coretext package, Apple provides a new API that allows us to make text layout easier</p></p><p><p>Create a Rich Text</p></p><p><p>nsmutableattributedstring *sttrias=[[nsmutableattributedstring alloc]initwithstring:@ "haha ha 1234567890"];</p></p><p><p>Change the style of different text in rich text</p></p><p><p>[sttrias addattribute:nsforegroundcolorattributename value:[uicolor bluecolor] range:nsmakerange (0, 3)];</p></p><p><p>[sttrias addattribute:nsfontattributename value:[uifont systemfontofsize:20] range:nsmakerange (0, 3)];</p></p><p><p>Set the number to red</p></p><p><p>[sttrias addattribute:nsforegroundcolorattributename value:[uicolor redcolor] range:nsmakerange (3, 10)];</p></p><p><p>[sttrias addattribute:nsfontattributename value:[uifont systemfontofsize:30] range:nsmakerange (3, 10)];</p></p><p><p>Add a picture</p></p><p><p>Nstextattachment *attch=[[nstextattachment alloc]init];</p></p><p><p>Attch.bounds=cgrectmake (0, 0, 32, 32);</p></p><p><p>Attch.image=[uiimage imagenamed:@ "8"];</p></p><p><p>Create rich text with a picture</p></p><p><p>Nsattributedstring *string=[nsattributedstring attributedstringwithattachment:attch];</p></p><p><p>[sttrias appendattributedstring:string];</p></p><p><p>Show</p></p><p><p>self.asdfhlabel.attributedtext=sttrias;</p></p><p><p>self.asdhagtextview.attributedtext=sttrias;</p></p><p><p></p></p><p><p>Http://www.cocoachina.com/industry/20131126/7417.html</p></p><p><p>Http://www.cocoachina.com/ios/20131028/7250.html</p></p><p><p>iOS Development Diary 21-7.0 after the text mix</p></p></span>
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