cbess / autoscrolllabel Goto Github PK
View Code? Open in Web Editor NEWProvides marquee like UILabel scrolling, think Music.app track title scrolling. For Obj-C & Swift.
License: MIT License
Provides marquee like UILabel scrolling, think Music.app track title scrolling. For Obj-C & Swift.
License: MIT License
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"
Hi,
as i said after closing and reopen the App the Scroll stops.
What can i do? Please help i´m a novice
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
The auto-scrolling should wait the pauseInterval
before it initially begins scrolling.
In my eyes the getter of "attributedText" should be "- (NSAttributedString *)attributedText" instead of "- (NSAttributedString *)setAttributedText"
ARC compatibility should be added
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?
How to put the autoscrolllabel inside titleview of navigationController's navigationBar?
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.
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...
It's not scrolling when text is "small" (for example "Full moon" not work).
Why?
当这个控件被当做一个 UITableViewCell 的subview时候,在 reloadData 时候指定了同一个 text,会出现不再滚动的问题
If possible it can be scrolling whatever the text is within bounds or not?
Hi,
text is always left aligned, when text is to short to scroll.
Hope there is a quick fixfor that.
Thanks,
Urkman
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
Hi can you support Carthage?
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.
At the start speed of scrolling is slower then after.
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
Hi
I need to pause the text for a while, this functionality is available in
https://github.com/cbpowell/MarqueeLabel
but i can not find it here so please let me know how it is possible to pause the scrolling. If i set the scrollSpeed=0 then the content shift to initial position.
Thanks
Hardik Shah
Allow this to work on the desktop (AppKit).
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;
}
Why is not working? the pod spec is commented :(
It is not work on real device with iOS13.7(iPhone7 Plus)
Text scrolls, then strangely disappears half-way through its scroll. Doesn't...seem right?
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.
Basically, I want to remove the label when the text in it has completely scrolled and then add another AutoScroll Label with another text. And keep doing that until the user clicks on one of those labels.
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
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?
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!!
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];
}
...
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!
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
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?
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
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;
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.
iWatch Screen is way smaller than other platforms, it's more useful on WatchOS I belive.
Hi.
First of all, great work! But will this framework available in swift (in the near future) ?
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;
}
Seems like iOS8 broke AutoScrollLabel
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.
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
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;
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
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];
}
...
}
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)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];
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.