IOS Marquee scroll bar Effect program code

Source: Internet
Author: User

The marquee effect of the scroll bar, generally appears at the bottom of iOS applications. Information used to display dynamic changes or long content, widely used in a class of applications
The following two types of Marqueebar are available for the rolling of the marquee.

1. Directly in the Viewcontroller to achieve the position of the uiview to achieve, the following code directly added to the Viewcontroller, in Viewwillappear call Loadview can.

The code is as follows Copy Code
-(void) Marqueeview
{

CGRect frame = self.vMarqueeContainer.frame;
frame.origin.x = frame.origin.x-2;
if (Frame.origin.x <-frame.size.width)
{
Frame.origin.x = 320;
}
Self.vMarqueeContainer.frame = frame;

Delay Recursive call
[Self performselector: @selector (Marqueeview) Withobject:nil afterdelay:0.04];
}

-(void) Loadview
{
Marqueenbar background, Position height control
UIView *viewmarqueebar = [[[UIView alloc]initwithframe:cgrectmake (0, 347,,)]autorelease];
[Viewmarqueebar Setbackgroundcolor:[uicolor Darkgraycolor]];

Scrolling container, showing scrolling range
UIView *viewmarqueecontainer = [[[UIView Alloc]initwithframe:cgrectmake (3, 360,)]autorelease];
[Viewmarqueecontainer Setbackgroundcolor:[uicolor Clearcolor]];
[Viewmarqueecontainer Setclipstobounds:yes];
[Viewmarqueecontainer Setopaque:yes];

Content
Uilabel *lblcontent = [[[Uilabel alloc] Initwithframe:cgrectmake (0, 0, 50,14)]autorelease];
[Lblcontent settext:@] Here is the scroll bar ... "];
[Lblcontent Settextcolor:[uicolor Whitecolor]];
[Lblcontent Setbackgroundcolor:[uicolor Clearcolor]];
[Lblcontent setfont:[uifont fontwithname:@ "Helvetica" size:12]];
[Lblcontent Setopaque:yes];

Self.view= Viewmarqueebar;
Self.vmarqueecontainer = Viewmarqueecontainer;

[Self.view Addsubview:viewmarqueecontainer];

[Self marqueeview];
}

2. Customize the scroll bar control, let view itself rolling up, through the constant mutual method call to implement loop scrolling
UIMarqueeBarView.h definition

The code is as follows Copy Code

/**
*uimarqueebarview.h
*/
@interface Uimarqueebarview:uiview
{
}

-(void) start;
-(void) stop;
@end

UIMARQUEEBARVIEW.M implementation

/**
*uimarqueebarview.m
*/

#import "UIMarqueeBarView.h"

@implementation Uimarqueebarview

-(void) dealloc
{
[Super Dealloc];
}

-(ID) initWithFrame: (CGRect) frame
{
self = [super Initwithframe:frame];
if (self) {
Initialization code
[Self setupview];
}
return self;
}

-(ID) Initwithcoder: (Nscoder *) Adecoder {
if (self = [super Initwithcoder:adecoder])) {
Initialization code
[Self setupview];
}
return self;
}

-(void) Setupview
{
[Self Setbackgroundcolor:[uicolor lightgraycolor]];
[Self setclipstobounds:yes];
[Self setopaque:yes];

Uilabel *lblcontent = [[[Uilabel alloc] Initwithframe:cgrectmake (0, 0,)]autorelease];
[Lblcontent settext:@] Here is the scroll bar ... "];
[Lblcontent Settextcolor:[uicolor Whitecolor]];
[Lblcontent Setbackgroundcolor:[uicolor Clearcolor]];
[Lblcontent setfont:[uifont fontwithname:@ "Helvetica" size:14]];
[Lblcontent setnumberoflines:1];
[Lblcontent Setopaque:yes];

[Self addsubview:lblcontent];
}

-(void) Start
{
if (Self.viewcontainer = = NULL) {
[Self setupview];
}

[Self startanimation];
}
-(void) stop
{

}

-(void) startanimation
{
[UIView beginanimations:@ "Marqueebaraniamation" context:nil];
[UIView Setanimationcurve:uiviewanimationcurvelinear];
[UIView setanimationduration:25];
[UIView setanimationdelegate:self];
[UIView setanimationdidstopselector: @selector (animationDidStop:finished:context:)];

CGRect viewframe = self.viewContainer.frame;
viewframe.origin.x =-320;
[Self.viewcontainer Setframe:viewframe];

[UIView commitanimations];
}

-(void) Animationdidstop: (NSString *) Animationid finished: (NSNumber *) finished context: (void *) context
{
CGRect viewframe = self.viewContainer.frame;
Viewframe.origin.x = 320;
[Self.viewcontainer Setframe:viewframe];
[Self startanimation];
}

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.