Friday 22 August 2014

Marquee Label & AttributedString - Sample code

Download or copy the Two Files. Added code into your project.

MarqueeLabel.h

MarqueeLabel.m

Download Sample Code 

.m File
#import "MarqueeLabel.h"

@interface ViewController ()
{
    MarqueeLabel  *marquee_lbl;
}

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

marquee_lbl = [[MarqueeLabel alloc]init];

NSString *newStr = @“Good for Health”;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:newStr];
    [attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@“Helvetica” size:11.0f] range:NSMakeRange(0, 3)];
    [attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica" size:14.0f] range:NSMakeRange(4, newStr.length-4)];
    marquee_lbl.attributedText = attributedString;

if ([marquee_lbl.text length] > 30)
            {
                marquee_lbl.marqueeType = MLContinuous;
                marquee_lbl.scrollDuration = 10.0;
                marquee_lbl.animationCurve = UIViewAnimationOptionCurveEaseInOut;
                marquee_lbl.fadeLength = 5.0f;
                marquee_lbl.continuousMarqueeExtraBuffer = 200.0f;
                marquee_lbl.tag = 102;
            }

}

No comments: