Function:
1, scrolling advertising Banner
Source Address:
https://github.com/SSBun/iOS-Custom-Control/tree/master/Rolling Banners (3)
// // BZScrollBar.h// bzscrollbar//// Created by Cai Shilin on 16/1/22. // copyright©2016 for the year BZ. All rights reserved. //#import <UIKit/UIKit.h>*datas; @end
////BZSCROLLBAR.M//Bzscrollbar////Created by Cai Shilin on 16/1/22.//copyright©2016 for the year BZ. All rights reserved.//#import"BZScrollBar.h"@interface Bzscrollbar () @property (Strong, nonatomic) Uiscrollview*ScrollView, @property (Strong, nonatomic) Nsmutablearray*Imageviewarr, @end @implementation Bzscrollbar-(Nsmutablearray *) imageviewarr{if(!_imageviewarr) {_imageviewarr=[Nsmutablearray array]; } return_imageviewarr;}-(Instancetype) initWithFrame: (cgrect) frame{ Self=[Super Initwithframe:frame]; if(self) {[self setupui]; } returnSelf ;}- (void) setupui{Uiscrollview*scrollview =[[Uiscrollview alloc]init]; Self.scrollview=ScrollView; Scrollview.pagingenabled=YES; [Self Addsubview:scrollview];}- (void) Setdatas: (Nsarray *) datas{_datas=datas; for(inti =0; I < Datas.count +2; i + +) {UILabel*label =[[UILabel alloc]init]; Label.textcolor=[Uicolor Whitecolor]; Label.backgroundcolor=[self randomcolor]; [Self.scrollview Addsubview:label]; Label.textalignment=Nstextalignmentcenter; Label.font= [Uifont systemfontofsize: the]; [Self.imageviewarr Addobject:label]; if(i = =0) {Label.text= Datas[datas.count-1]; } Else if(i = = Datas.count +1) {Label.text= datas[0]; Label.backgroundcolor= ((UILabel *) self.imageviewarr[1]). BackgroundColor; } Else if(i = =datas.count) {Label.text= Datas[i-1]; Label.backgroundcolor= ((UILabel *) self.imageviewarr[0]). BackgroundColor; } Else{Label.text= Datas[i-1]; }} [self setneedslayout]; [Self layoutifneeded]; [Nstimer scheduledtimerwithtimeinterval:2target:self selector: @selector (ScrollBar) Userinfo:nil repeats:yes];}-(Uicolor *) randomcolor{cgfloat Red= ((Arc4random ()%255) +1) /255.0; CGFloat Green= ((Arc4random ()%255) +1) /255.0; CGFloat Blue= ((Arc4random ()%255) +1) /255.0; return[Uicolor colorwithred:red green:green blue:blue Alpha:1];}- (void) layoutsubviews{[Super Layoutsubviews]; Self.scrollView.frame=Self.bounds; Self.scrollView.contentOffset= Cgpointmake (0, Self.bounds.size.height); CGFloat W=Self.bounds.size.width; CGFloat H=Self.bounds.size.height; Self.scrollView.contentSize= Cgsizemake (1, Self.imageViewArr.count *self.bounds.size.height); for(inti =0; i < Self.imageViewArr.count; i + +) {UILabel*label =Self.imageviewarr[i]; Label.frame= CGRectMake (0HI, W, H); }}- (void) scrollbar{if(Self.scrollview.contentoffset.y >= Self.scrollView.contentSize.height-self.scrollView.bounds.size.height) {Self.scrollView.contentOffset= Cgpointmake (0, Self.scrollView.bounds.size.height); } cgpoint Point=Self.scrollView.contentOffset; Point.y= Point.y +Self.scrollView.bounds.size.height; [UIView animatewithduration:1animations:^{Self.scrollView.contentOffset=Point ; }];} @end
Custom Controls (3)-scrolling banner