Custom Controls (3)-scrolling banner

Source: Internet
Author: User

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

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.