IOS is similar to the Netease news homepage news carousel component.

Source: Internet
Author: User

IOS is similar to the Netease news homepage news carousel component.
Requirement Analysis 1. News images can be rolled horizontally and cyclically. 2. News Titles are displayed when the corresponding images are rolled. 3. Each news image can be clicked. 4. pageControl tip. 5. Control scalability ii. Design and Implementation 1. Use SDWebImage third-party library to display images, cache images, asynchronously load images through URLs 2. Use a horizontal scroll UITableView to achieve circular scrolling 3. Use a black translucent background and a white text UILabel to display Titles 4. Define each news data structure: /** @ brief uses the local address by default. If not, use the network image */@ interface PhotoNewsModel: NSObject/** @ image displayed during brief loading */@ property (nonatomic, strong) UIImage * loadingImage;/** @ brief image local address */@ property (nonatomic, strong) NSString * localPath;/** @ brief news image address */@ property (nonatomic, strong) NSString * photoUrl; /** @ brief news title */@ property (nonatomic, strong) NSString * title; @ end5, proxy protocol: @ protocol UIPhotoNewsViewDelegate <NSObject>/*** obtain the number of image news items ** @ param photoNews control ** @ return the number of image news items */-(NSUInteger) photoNewsCount :( UIPhotoNewsView *) photoNews; /*** return the model of the first image news ** @ param photoNews control * @ param index ** @ return returns the model */-(PhotoNewsModel *) that describes the image news *) photoNews :( UIPhotoNewsView *) photoNews photoModelAtIndex :( NSUInteger) index; /*** callback of image news click ** @ param photoNews control * @ param model click the model corresponding to the news */-(void) photoNews :( UIPhotoNewsView *) photoNews photoDidClick :( PhotoNewsModel *) model; @ end6. How to Implement Circular scrolling?) copy a copy of the data to be displayed, which is equivalent to 1, 2, 3, 4 | 1, 2, 3, and 4 B). When initializing the data, locate the second copy. Here c) when you scroll to the previous 1 or 2, set to jump to the second 1 and 2 d) key code:-(void) makeCycleScroll {if (self. realCount> = 2) {CGFloat currentOffsetX = self. contentTableView. contentOffset. x; CGFloat currentOffSetY = self. contentTableView. contentOffset. y; CGFloat contentHeight = self. contentTableView. contentSize. height; if (currentOffSetY <(contentHeight/8.0) {self. contentTableView. contentOffset = CGPointMake (currentOffsetX, (currentOffSetY + (contentHeight/2);} if (currentOffSetY> = (contentHeight * 6)/8.0) {self. contentTableView. contentOffset = CGPointMake (currentOffsetX, (currentOffSetY-(contentHeight/2 )));}}}

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.