Swift Head Wireless Carousel View

Source: Internet
Author: User

////Amoncirheadview.swift//Bqpreader////Created by Mac on 16/5/25.//copyright©2016 year BQP. All rights reserved.//Import UIKitclassAmoncirheadview:uiview, uiscrollviewdelegate{var dataarray:nsarray?; var _scrollview:uiscrollview?;
Timer var _timer:nstimer?;
The main purpose is to determine the display position of ScrollView and Pagecontroller var index:int64?; var _pagecontrol:uipagecontrol?; OverrideInit (frame:cgrect) {super.init (frame:frame);
Copy all the code to insert the picture, change the picture name here, of course, you can also request a picture network, this yourself to modify the logic bar DataArray= ["aion01.jpg","aion02.jpg","aion03.jpg"];
Create ScrollView _scrollview= Uiscrollview (Frame:cgrectmake (0,0, Kscreenw,self.bounds.size.height)); _scrollview?. Bounceszoom =false; _scrollview?. bounces =false; _scrollview?. Showshorizontalscrollindicator =false; _scrollview?. Showsverticalscrollindicator =false; _scrollview?. pagingenabled =true; _scrollview?.Delegate=Self ; Self.addsubview (_scrollview!); _scrollview?. Contentsize = Cgsizemake (Self.bounds.size.width * cgfloat (DataArray?. Count)!), self.bounds.size.height); _scrollview?. BackgroundColor =Uicolor.redcolor ();
Create Pagecontrol _pagecontrol= Uipagecontrol (Frame:cgrectmake (0, Self.bounds.size.height- -, Kscreenw, -)); Self.addsubview (_pagecontrol!); _pagecontrol!. BackgroundColor =Uicolor.clearcolor (); _pagecontrol!. Numberofpages = (DataArray?. Count)!; _pagecontrol!. CurrentPage =0; _pagecontrol!. Pageindicatortintcolor =Uicolor.whitecolor (); _pagecontrol!. Currentpageindicatortintcolor =Uicolor.orangecolor (); Creatimageview (); } Required Init?(coder Adecoder:nscoder) {fatalerror ("Init (coder:) has not been implemented")}//Create a picture control on ScrollView func Creatimageview () {index=0; var i=0; forImgnmaeinchdataarray!{Let IMGV= Uiimageview (Frame:cgrectmake (self.bounds.size.width * cgfloat (i),0, Self.bounds.size.width, self.bounds.size.height)); Imgv.image= UIImage (Named:imgnmae as!String); _scrollview?. Addsubview (IMGV); I= i +1; }//Create timer _timer= Nstimer.scheduledtimerwithtimeinterval (3, Target:self, selector:"Timemethod", Userinfo:nil, repeats:true);
Create Runloop to set the operating mode of the timer, ensuring that the timer is also working nsrunloop.currentrunloop () when sliding the interface. AddTimer (_timer!, Formode:nsrunloopcommonmodes); }//Timer called method func Timemethod () {index= index!+1; ifNsinteger (index!) >= DataArray?. count{Index=0; } uiview.animatewithduration (0.35) {(), VoidinchSelf._scrollview!. Contentoffset = Cgpointmake (CGFloat (self.index!) * Kscreenw, self._scrollview!. Contentoffset.y); }; _pagecontrol!. CurrentPage = Nsinteger (index!); }//scrollview proxy func scrollviewdidscroll (scrollview:uiscrollview) {Let x= scrollview.contentoffset.x/Kscreenw; Index=Int64 (x); _pagecontrol!. CurrentPage =Nsinteger (x); } }

Swift Head Wireless Carousel View

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.