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]; } |