Use third-party class libraries for carousel images and iOS class libraries for ios development

Source: Internet
Author: User

Use third-party class libraries for carousel images and iOS class libraries for ios development

There are many third-party class libraries on github, which greatly saves everyone's development time.

: Https://github.com/gsdios/SDCycleScrollView

Cocoapods import: pod 'sdcyclescrollview', '~> 1.61'

 

Effect

 

 

Specific implementation code

# Import "ViewController. h "# import" SDCycleScrollView. h "@ interface ViewController () <SDCycleScrollViewDelegate> @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; self. view. backgroundColor = [UIColor colorWithRed: 0.98 green: 0.98 blue: 0.98 alpha: 0.99]; UIImageView * backgroundView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @ "005.jpg"]; backgroundView. frame = self. view. bounds; [self. view addSubview: backgroundView]; UIScrollView * demoContainerView = [[UIScrollView alloc] initWithFrame: self. view. frame]; demoContainerView. contentSize = CGSizeMake (self. view. frame. size. width (1200); [self. view addSubview: demoContainerView]; self. title = @ "Carousel Demo"; // scenario 1: NSArray * imageNames = @ [@ "h1.jpg", @ "h2.jpg", @ "h3.jpg ", @ "h4.jpg", @ "h7" // enter the full name of the local image]; // Scenario 2: NSArray * imagesURLStrings = @ [@ "https://ss2.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=a4b3d7085dee3d6d2293d48b252b5910/0e2442a7d933c89524cd5cd4d51373f0830200ea.jpg ", @ "https://ss0.baidu.com/-Po3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=a41eb338dd33c895a62bcb3bb72e47c2/5fdf8db1cb134954a2192ccb524e9258d1094a1e.jpg", @ "http://c.hiphotos.baidu.com/image/w%3D400/sign=c2318ff84334970a4773112fa5c8d1c0/b7fd5266d0160924c1fae5ccd60735fae7cd340d.jpg"]; // Scene 3: picture with text NSArray * titles = @ [@ "New Communication QQ group: 185534916 ", @ "thanks for your support, if you download", @ "if the Code has problems in use", @ "you can mail to the gsdios@126.com"]; CGFloat w = self. view. bounds. size. width; // >>>>>>>>>>>>>>>>>>>>>>>>> demo carousel Diagram 1 >>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> // load locally --- create an image carousel without a title, SDCycleScrollView * cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame: CGRectMake (0, 64, w, 180) shouldInfiniteLoop: YES imageNamesGroup: imageNames]; cycleScrollView. delegate = self; cycleScrollView. pageControlStyle = SDCycleScrollViewPageContolStyleAnimated; [demoContainerView addSubview: cycleScrollView]; // --- carousel interval. The default value is 1.0 seconds. You can customize it. // cycleScrollView. autoscrolltimeinteger = 4.0; // >>>>>>>>>>>>>>>>>>>>>>>>> demo carousel Image 2 >>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>/// network load --- create a title image carousel SDCycleScrollView * cycleScrollView2 = [SDCycleScrollView cycleScrollViewWithFrame: CGRectMake (0,280, w, 180) delegate: self placeholderImage: [UIImage imageNamed: @ "placeholder"]; dependencies = dependencies; cycleScrollView2.titlesGroup = titles; tags = [UIColor whiteColor]; // custom page control circle color [demoContainerView addSubview: cycleScrollView2]; // --- simulate loading delay dispatch_after (dispatch_time (interval, (int64_t) (0.3 * NSEC_PER_SEC )), dispatch_get_main_queue (), ^ {token = imagesURLStrings;});/* cycleScrollView2.clickItemOperationBlock = ^ (NSInteger index) {NSLog (@ ">>>>% ld ", (long) index );}; * // >>>>>>>>>>>>>>>>>>>>>>>>> demo carousel diagram 3 >>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>> // network load --- create the pageControlDot image carousel SDCycleScrollView for the custom image * cycleScrollView3 = [SDCycleScrollView cycleScrollViewWithFrame: CGRectMake (0,500, w, 180) delegate: self placeholderImage: [UIImage imageNamed: @ "placeholder"]; Parameters = [UIImage imageNamed: @ "pageControlCurrentDot"]; watermark = [UIImage imageNamed: @ "pageControlDot"]; Progress = watermark; [demoContainerView addSubview: cycleScrollView3];} # pragma mark-exclude-(void) cycleScrollView :( SDCycleScrollView *) cycleScrollView didSelectItemAtIndex :( NSInteger) index {NSLog (@ "--- click the % ld image", (long) index); [self. navigationController pushViewController: [NSClassFromString (@ "DemoVCWithXib") new] animated: YES];}/* // scroll to the desired image callback-(void) cycleScrollView (SDCycleScrollView *) cycleScrollView didScrollToIndex :( NSInteger) index {NSLog (@ ">>>>>> scroll to the % ld graph", (long) index);} */@ end

 

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.