iOS development using UIWebView for graphics and text blending

Source: Internet
Author: User

At the beginning of the first news project, do not know the use of UIWebView to achieve the effect of illustrations, so the most stupid way to use the TableView to solve the news browsing. When a little project experience is known to be possible with UIWebView or Coretext implementations, there has been no attempt. When the last interview was asked how to use WebView for the news display, then the circle. Come back, check the data found so simple, the original transfer from http://blog.csdn.net/wildcatlele/article/details/38583731 reprint please specify.

1. Okay, nonsense. First introduce, the main function of this demo, you can display the news content (picture and text mixed), links can be clicked to the original news page;

2. Look at the effect below:




Steps:

0. Create two view control bodies

Create a new project, and then create two controllers Lvesviewcontroller and Lvesoriginalcontroller

Add one UIWebView to Self.view, respectively.

1. Remove the webview when rolling, the white edge of the upper and lower.

-(void) Clearwebviewbackground: (UIWebView *) webview{    UIWebView *web = WebView;    For (ID v in web.subviews) {        if ([V Iskindofclass:[uiscrollview class]]) {            [v setbounces:no];        }    }


2. Setting up the agent

2. Set proxy    self.mywebview.delegate=self;


3. Add a view that loads WebView

#pragma mark load webview-(void) loadmywebview{nsstring *[email protected] "Han cold after will be endless" wonderful gold suction 3 cheats "; NSString *linkstr=[nsstring stringwithformat:@ "<a href= '%@ ' > My blog </a> <a href= '%@ ' > Original </a>" @        "Http://blog.csdn.net/wildcatlele", @ "http://jincuodao.baijia.baidu.com/article/26059"]; NSString *[email protected] "Han cold" after will be endless "the ability to absorb gold surprised me! 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.        "; NSString *[email protected] "You know," after the will be "is not the mainstream genre film, is a literary film. Unlike "little Times", is a mainstream business idol movie.    "; NSString *image1=[nsstring stringwithformat:@ " ', @" http://nvren.so/    Uploads/allimg/c140801/140dr4554l40-yb9.jpg "]; NSString *image2=[nsstring stringwithformat:@ " ', @"/http f.hiphotos.baidu.com/news/w%3d638/sign=78315beeb1fb43161a1f797918a44642/        2934349b033b5bb58cb61bdb35d3d539b600bcb5.jpg "]; 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 a 30 million fan movie "I Am Me", a star, the production is also good, basically a fiasco.        "; 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. <br> is very vicious, worthy of reference. 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.        "; Initialization and HTML string nsstring *htmlurlstr=[nsstring stringwithformat:@ "<body style= ' background-color: #EBEBF3 ' >< h2>%@


4. Implementing the Proxy method (handling connection click events)

-(BOOL) WebView: (UIWebView *) WebView shouldstartloadwithrequest: (nsurlrequest *) Request Navigationtype: ( Uiwebviewnavigationtype) navigationtype{    nsstring *urlstr=request. url.absolutestring;        NSLog (@ "URL:%@", urlstr);        Empty, the first time this page is loaded    if ([Urlstr isequaltostring:@ "About:blank"]) {        return YES;    }        Set the post-click View Controller    lvesoriginalcontroller *originalc=[[lvesoriginalcontroller alloc] init];    ORIGINALC.ORIGINURL=URLSTR; Set the request    to connect//jump to the post-click Controller and Load WebView    [Self.navigationcontroller pushviewcontroller:originalc animated:yes];        return  NO;} Set bottom scroll not bounce-(void) Webviewdidfinishload: (UIWebView *) webview{    Nsinteger height = [[WebView stringbyevaluatingjavascriptfromstring:@ "Document.body.offsetHeight;"] Intvalue];    nsstring* JavaScript = [NSString stringwithformat:@ "Window.scrollby (0,%d);", height];    [WebView Stringbyevaluatingjavascriptfromstring:javascript];}


5. Implement Origainalviewcontroller

  lvesoriginalcontroller.m//  webviewdemo////  Created by lves Li on 14-8-15.//  Copyright (c) 2014 Lves. All rights reserved.//#import "LvesOriginalController.h" @interface Lvesoriginalcontroller () {    UIWebView *_ WebView;} @end @implementation lvesoriginalcontroller-(ID) initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) nibbundleornil{self    = [super Initwithnibname:nibnameornil Bundle:nibbundleornil];    if (self) {        //Custom initialization    }    return to self;} -(void) viewdidload{    [Super Viewdidload];    Set title    [email protected] "original";            _webview=[[uiwebview alloc] init];    _webview.frame=[[uiscreen Mainscreen] bounds];        [Self.view Addsubview:_webview];        [_webview loadrequest:[nsurlrequest Requestwithurl:[nsurl URLWithString:self.originUrl]];        } @end


Download connection








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.