Code Monkey home page Code Monkey logo

autoscrolllabel's People

Contributors

bryant1410 avatar cbess avatar chaingarden avatar ipodishima avatar mdewolfe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autoscrolllabel's Issues

Long Text Not Supporting

Hi I have a long text to scroll but when i try it does not show anything. it supported up to some length of text. How to resolve it please let me know

When i pass long text it crash the application.Like below

@"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniamLorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniamLorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniamLorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam"

iOS 8 sizeWithFont deprecated

due to the fact that sizeWithFont is deprecated in IOS8 there is a need to change this:

CGSize labelSize = [self.mainLabel.text sizeWithFont:self.mainLabel.font
                                       constrainedToSize:CGSizeMake(CGFLOAT_MAX,    
                                       CGRectGetHeight(self.bounds))];

with:

CGRect labelSize = [self.mainLabel.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 
                                CGRectGetHeight(self.bounds))
                                options:NSStringDrawingUsesLineFragmentOrigin
                                attributes:@{NSFontAttributeName:self.mainLabel.font}
                                context:nil];

and them change the labelSize.width for labelSize.size.width

Misspelled getter method

In my eyes the getter of "attributedText" should be "- (NSAttributedString *)attributedText" instead of "- (NSAttributedString *)setAttributedText"

Still can't get it to work...

  1. I have created all the autoscrolllabel .h and the .m files and lastly the macro.h file
  2. Included the autoscrolllabel.h header file in my ViewController file
  3. Added the IBOutlet AutoScrollLabel *autoScrollLabel; in the ViewController.h file (do I need to add @Property for the IBOutlet?????)
  4. Created a UIScrollView in the ViewController.m file as such:
    // Alocate and initialize scroll
    UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(120.0f, 0.0f, 320.0f, 60.0f)];
    scroll.contentSize = CGSizeMake(320, 700);
    scroll.showsHorizontalScrollIndicator = YES;
  5. Created the autoScrollLabel as such:
    autoScrollLabel.text = @"This text may be clipped, but now it will be scrolled.";
    autoScrollLabel.textColor = [UIColor blueColor];
    autoScrollLabel.labelSpacing = 35; // distance between start and end labels
    autoScrollLabel.pauseInterval = 3.7; // seconds of pause before scrolling starts again
    autoScrollLabel.scrollSpeed = 30; // pixels per second
    autoScrollLabel.textAlignment = UITextAlignmentCenter; // centers text when no auto-scrolling is applied
  6. Finally I added both the autoScrollText and the UIScrollView to the ViewController as such:
    // add autoScrollLabel
    [scroll addSubview:autoScrollLabel];
    // add scroll view to main view
    [self.view addSubview:scroll];
    // release label and scroll view
    [autoScrollLabel release];
    [scroll release];

When I run in simulator, the UIScrollView is present as i can see the scrolling bars when I pull on the area I created for the UIScrollView, but there is not text that is present and thus does not auto scroll?

Can you please let me know what I am missing?

Marquee stops scrolling

Line 285 ff contains:

// setup pause delay/loop
if (finished) {
 [self performSelector:@selector(scrollLabelIfNeeded) withObject:nil];
}

If the completion block of the animation is called with finished equal to NO, then the marquee will stop and refuse to start back up. This is something that happens on occasion while the app is running.

CPU Overhaul

When the text is longer and needs to scroll this sometimes takes my CPU from 10% to 100%! I noticed when pausing while it was at 100% that the method: - (void)scrollLabelIfNeeded was being executed. It was on the main thread for a while and all the other animations in my app stopped. It makes this hard to use especially since I only have one label...

textAlignment not working

Hi,

text is always left aligned, when text is to short to scroll.
Hope there is a quick fixfor that.

Thanks,
Urkman

iOS 8 - weird behaviour on restore from background

iOS 8 (iOS 8 simulator only, works well on iOS 7 by default) - move app to background then to foreground:
text move at higher speed (then specified), text disappear on scroll finish

Fixed by adding UIViewAnimationOptionBeginFromCurrentState to
self.animationOptions = UIViewAnimationOptionCurveEaseIn;

also unclear why to observe UIApplicationWillEnterForegroundNotification if already track UIApplicationDidBecomeActiveNotification event

Vertical Scroll

Can you add vertical scroll and multiple line support? I am building out a tvOS app and I have a set size for a description. I want it to fill that size and if there is more text scroll the text upwards.

AutoScrollLabel width not autoresizing in UINavigationBar (titleView)

I've placed an AutoScrollLabel as a titleView in the Navigation Item of a UIViewController, which is in a UINavigationController stack. The AutoScrollLabel should fill out the entire space between the left and right UIBarButtonItem.
In portrait mode this works well, but as soon as I turn the device in landscape mode, the AutoScrollLabel keeps its width and stays centered instead of getting autoresized and filling out the space between the 2 UIBarButtonItems as before.

I really appreciate any help

Thanks Linard

AutoScrollLabel doesn't show text when text is large

When I set text which is very large, like more than 300 characters, text doesn't appear on label.

This is how I configured newsLabel AutoScrollLabel. Frame is set from XIB:

- (void) updateNews:(NSString *) news {
    
    self.newsLabel.textColor = [UIColor blackColor];
    self.newsLabel.font = [UIFont systemFontOfSize:14];
    self.newsLabel.labelSpacing = 0.0; // distance between start and end labels
    self.newsLabel.pauseInterval = 0.0; // seconds of pause before scrolling starts again
    self.newsLabel.scrollSpeed = 30; // pixels per second
    self.newsLabel.textAlignment = NSTextAlignmentLeft; // centers text when no auto-scrolling is applied
    self.newsLabel.fadeLength = 12.f;
    self.newsLabel.scrollDirection = CBAutoScrollDirectionLeft;
    
    self.newsLabel.text = news;
}

Scroll rate appears to be non-linear

It appears that the scroll rate starts slow, then speeds up towards the middle of the text, and then slows down again before stopping, following a bell curve rather than a flat line.

I haven't quite figured out what makes it behave that way, but it's not particularly desirable for my use case.

How to install pod with Swift

I am a beginner at programming, and an extreme beginner at CocoaPods.

https://github.com/cbess/AutoScrollLabel

Trying to figure out how to install this pod. I am using Swift and trying to create something with tvOS. This link says it supports both. Can someone take me through the process of installing the pod.

I have saved the project to my desktop and cd'ed into it, and I don't know wh

iOS 6.1 XCode 4.6

I have been using this library for a long time but now is the first time in XCode 4.6.
And how ever I try to get the UIScrollView to use the class I cannot.

What am I doing wrong?

Text vanishes on iOS 8, followed by appearing to scroll, then vanishes again.

Hey all,

Just noticed that when the text view appears on iOS 8 that it will vanish right away, followed by a scroll after a delay. When the animation is due to slow down and stop (*or just stop depending on your UIViewAnimationCurve setting) it disappears again.

I thought it was because of the deprecated NSString method we had to replace all the old stuff with, but alas no avail.

I do manually call [scrollLabelIfNeeded] when I return from the background on my app, is this causing the issue or is this just to do with outdated code and iOS 8's changes that Apple never publicise?

Thanks!!

Scrolling issue if text gets loaded in viewWillAppear

I add my text for the scrollLabel in viewWillAppear. For this reason, the AutoScrollLabel is at startup non scrolling and in my case centered. If I add now scrollable content, the mainLabel is still centered and the 2nd label not. For this reason the scrollLabel "jumps" after the animation to the start position.
Here is my fix:
CBAutoScrollLabel.m "-(void)refreshLabels":

 ...
 // if the label is bigger than the space allocated, then it should scroll
if (CGRectGetWidth(self.mainLabel.bounds) > CGRectGetWidth(self.bounds) )
{
    CGSize size;
    size.width = CGRectGetWidth(self.mainLabel.bounds) + CGRectGetWidth(self.bounds) + self.labelSpacing;
    size.height = CGRectGetHeight(self.bounds);
    self.scrollView.contentSize = size;
 /*******************************************************************/
 //This is new:
    self.mainLabel.textAlignment = UITextAlignmentLeft;
 /*******************************************************************/

    EACH_LABEL(hidden, NO)

    [self applyGradientMaskForFadeLength:self.fadeLength enableFade:self.scrolling];

    [self scrollLabelIfNeeded];
}
else
{
    // Hide the other labels
    EACH_LABEL(hidden, (self.mainLabel != label))

    // adjust the scroll view and main label
    self.scrollView.contentSize = self.bounds.size;
    self.mainLabel.frame = self.bounds;
    self.mainLabel.hidden = NO;
    self.mainLabel.textAlignment = self.textAlignment;

    [self applyGradientMaskForFadeLength:0 enableFade:NO];
}
 ...

I works, but not enough

major function are base on animation of IOS, it works, but not flexible, I need a drag function not just auto scroll. it's marvellous that the whole iOS world do not have a second better customise label!

memory management

first i want to thank you very much for the code.
here is my error. when i run the "analyze" tool form xcode
i get the following message:
Potential leak of an object allocated on line 85

85 self.labels = [labelSet.allObjects copy];
86 NSRelease(labelSet)

can i just ignore that error or will apple reject my app for this.

with kind reagards,

thomas

I followed all your steps but I still dont see any scrolling text

Have created both the autoscrolllabel .h and the .m and macro.h file.

Placed the
IBOutlet AutoScrollLabel *autoScrollLabel;
in the ViewController.h file (do I need to add @Property for the IBOutlet?????)

In the veiwcontroller .m file I have the following:
autoScrollLabel.text = @"This text may be clipped, but now it will be scrolled.";
autoScrollLabel.textColor = [UIColor blueColor];
autoScrollLabel.labelSpacing = 35; // distance between start and end labels
autoScrollLabel.pauseInterval = 3.7; // seconds of pause before scrolling starts again
autoScrollLabel.scrollSpeed = 30; // pixels per second
autoScrollLabel.textAlignment = UITextAlignmentCenter; // centers text when no auto-scrolling is applied

What am I missing to get this to work. Do you have a working sample code?

How to start scrolling after some offset of text

Hi

I have one condition like i want to start scrolling in the middle of some text not from the starting of the text how can i do that?

Example : like i have UISlider at the bottom of the screen and using sliding i am shifting the content of the text and now at this point i want to plat text scrolling. How to start text scrolling at given point.

Thanks
Hardik

Please update your -(void)refreshLabels

It could be something issue is iOS 7

  • (void)refreshLabels
    {
    __block float offset = 0;

    // calculate the label size
    // CGSize labelSize = [self.mainLabel.text sizeWithFont:self.mainLabel.font
    // constrainedToSize:CGSizeMake(CGFLOAT_MAX, CGRectGetHeight(self.bounds))];

UIFont *font = self.mainLabel.font;

if (!self.mainLabel.text) {
    return;
}

NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:self.mainLabel.text attributes:@{NSFontAttributeName:font}];

CGRect rect = [attributedText boundingRectWithSize:(CGSize){CGFLOAT_MAX, CGRectGetHeight(self.mainLabel.bounds)}
                                           options:NSStringDrawingUsesLineFragmentOrigin
                                           context:nil];
CGSize labelSize = rect.size;

2 instances in same view

Using the former version of this code I was able to have two instances of Autoscroll label running on the same view.

Dropping your updated files into the project, only the first instance animates, the second instance remains static, with the text offset to the right by about half the screen.

Support for WatchOS

iWatch Screen is way smaller than other platforms, it's more useful on WatchOS I belive.

Q: Swift ?

Hi.

First of all, great work! But will this framework available in swift (in the near future) ?

Resizing issue

When you add autoscrolllabel to your project, set a uiview in Interface Builder and put autoscroller inside the uiview.
Then you go into the ruler and set the sizing to lock right, left, make all views cut subviews.

Then when you resize the uiview that is parent view to the autoscroller the autoscroller will not resize correctly.

In short, lock size, resize superview and autoscroller will not resize correctly.

Here is a simple code from a test project :
This is just a button that resizes the parent view to autoscrolllabel. As simple as it gets.

- (IBAction)resize:(id)sender {
    CGRect frame = backgroundView.frame;
     frame.size.width -= 30;

    backgroundView.frame = frame;

}

Creation with just init

When I'm creating the instances of the labels, theres no way for me to know the frames of the labels and thus I can't use initWithFrame. Is there a way to add an init method? After looking through, I'm guessing there'd be some issues with setting both the scroll view and label frames.

Change text or attributedText without restarting scroll animation

Hi,

I have quite a few updates for the AutoScrollLabel (sometimes up to every 3 seconds).
The text has more or less always the same length and if not, I add some spaces, that as often as possible the new text has the same length as the old text.

I've tried modifying the method "setAttributedText: refreshLabels:" and similar "setText: refreshLabels:" as following:

  • (void)setAttributedText:(NSAttributedString *)theText refreshLabels:(BOOL)refresh
    {
    // ignore identical text changes
    if ([theText.string isEqualToString:self.attributedText.string])
    return;

    EACH_LABEL(attributedText, theText)

    //Custom Modification:
    if (theText.length == currentLabelLength)
    return;

    if (refresh)
    [self refreshLabels];
    }

currentLabelLength contains the length of the current displayed text.
If I step over it, I can see, that I get the return as intended, but the scroll animation starts at the beginning.
The problem is now, that because of my often updates, the user is not able to read the entire label, before the scroll animation restarts.

Does someone know a solution or another approach?

Thank you for any help

Linard

Small enhancement on animation

I had two problems with the scrolling animation. First, at the very end of the animation, the label is making a 1 point jump. Second, just after the animations ends, the front fade disappear suddenly.

Here are my adjustements so that the label ends its animation exactly at the right place (not making a small jump like before). Also, I split the animation in two parts, so I can remove the front fade before the label arrives at the beggining of the view.

in - (void)scrollLabelIfNeeded:

NSTimeInterval duration = labelWidth / self.scrollSpeed;
NSTimeInterval duration2 = (self.labelSpacing - 1.0) / self.scrollSpeed;

[UIView animateWithDuration:duration delay:self.pauseInterval options:self.animationOptions | UIViewAnimationOptionAllowUserInteraction animations:^{
    // adjust offset
    self.scrollView.contentOffset = (doScrollLeft ? CGPointMake(labelWidth, 0) : CGPointMake(self.labelSpacing + 1.0, 0.0));
} completion:^(BOOL finished) {
    if (finished) {
        // remove the left shadow
        [self applyGradientMaskForFadeLength:self.fadeLength enableFade:NO];

        [UIView animateWithDuration:duration2 delay:0.0 options:self.animationOptions | UIViewAnimationOptionAllowUserInteraction animations:^{
            // adjust offset
            self.scrollView.contentOffset = (doScrollLeft ? CGPointMake(labelWidth + self.labelSpacing - 1.0, 0) : CGPointZero);
        } completion:^(BOOL finished) {
            _scrolling = NO;

            // setup pause delay/loop
            if (finished)
            {
                [self performSelector:@selector(scrollLabelIfNeeded) withObject:nil];
            }
        }];
    } else {
        _scrolling = NO;
    }
}];

Don't forget to add this in - (void)refreshLabels:

[self.scrollView.layer removeAllAnimations];

Right after:

self.scrollView.contentOffset = CGPointZero;

Scrolling stops after transition to another UIViewController and back again

Hi,
I am seeing a problem where I have an AutoScrollLabel which scrolls fine. However, when I transition to another UIView and back to the view with the scrolling label the scrolling has stopped and will not re-start.

What seems to be happening is that when 'viewWillDisappear' is called in from main UIViewController containing the AutoScrollLabel, the processes scrolling the label are stopped by iOS but the '_scrolling' flag is not set to "NO". When I return to the UIViewController containing the AutoScrollLabel it will not start because the test in 'scrollLabelIfNeeded' at:

if (labelWidth <= CGRectGetWidth(self.bounds) || self.scrolling) {
    return;
}

fails because 'self.scrolling' equals "YES" due to the completion block never being completed.

I have tried all sorts of things to get around this problem, including adding a setter to force 'scrolling' to "NO" (and changing from readonly)but nothing I have tried works.

Can you suggest a solution??

Thanks, Andrew

Possible attributedText issue

Update: Sorry I was wrong. I'm using CBAutoScrollLabel with attributed strings, but [attributedText size] returns a smaller width than [text sizeWithFont:], so that the label is to short for my string. As long as the attributedText has the same font size as the text property, there isn't an issue.

If self.mainLabel.attributedText contains a different text than self.mainLabel.text or if the text is styled differently (e.g. different font size), the label size gets wrong calculated.
Here's my fix (in CBAutoScrollLabel.m):
If the text property gets set, set the attributedText nil and vice versa:

 - (void)setText:(NSString *)theText refreshLabels:(BOOL)refresh
 {
     ...
     EACH_LABEL(text, theText)
     EACH_LABEL(attributedText, nil)
     ...
}

 - (void)setAttributedText:(NSAttributedString *)theText refreshLabels:(BOOL)refresh
 {
     ...
     EACH_LABEL(attributedText, theText)
     EACH_LABEL(text, nil)
     ...
}

And calculate the label size depending on which property is set:

 - (void) refreshLabels
 {
      ...
      // calculate the label size
      CGSize labelSize = CGSizeZero;

      if (self.mainLabel.text != nil)
      {
           labelSize = [self.mainLabel.text sizeWithFont:self.mainLabel.font
                                   constrainedToSize:CGSizeMake(CGFLOAT_MAX, CGRectGetHeight(self.bounds))];
      }
      else  if (self.mainLabel.attributedText != nil)
      {
           labelSize = [self.mainLabel.attributedText size];
      }
      ...
 }

Scroll label in tableview stops when changing tabs.

I have a scrolling label in a table cell that works on first load. When changing tabs or views and switching back the label no longer scrolls in the table.

I have tried the following:

-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:true];
[self playlistTableSetup];
}

// Playlist Table Setup

  • (void)playlistTableSetup{
    playlistTableVC = [self.storyboard instantiateViewControllerWithIdentifier:@"PlaylistTable"];
    playlistTableVC.view.frame = CGRectMake(0, 70, 320, self.view.bounds.size.height-170);
    [self.view addSubview:playlistTableVC.view];
    [self addChildViewController:playlistTableVC];
    }

-(void)viewDidDisappear:(BOOL)animated{
[playlistTableVC removeFromParentViewController];
playlistTableVC = nil;
}

This seems to adds a table over the existing and I have a opaque background so you can see multiple tables overlaying one another.

I have also tried reloading the data:
-(void)viewDidAppear:(BOOL)animated{
[playlistTable reloadData];
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.