diff --git a/MarqueeLabel.m b/MarqueeLabel.m index a878a6ef..33af8a7c 100755 --- a/MarqueeLabel.m +++ b/MarqueeLabel.m @@ -1157,12 +1157,16 @@ - (void)setMinimumScaleFactor:(CGFloat)minimumScaleFactor { - (void)refreshSubLabels:(NSArray *)subLabels { for (UILabel *sl in subLabels) { - sl.attributedText = self.attributedText; + if (sl.tag == 700) { + // Do not overwrite base subLabel properties + continue; + } sl.backgroundColor = self.backgroundColor; sl.textColor = self.textColor; sl.shadowColor = self.shadowColor; sl.shadowOffset = self.shadowOffset; sl.textAlignment = NSTextAlignmentLeft; + sl.attributedText = self.attributedText; } } @@ -1336,7 +1340,15 @@ - (NSArray *)gradientColors { } - (NSArray *)allSubLabels { - return [self.subviews filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"tag >= %i", 700]]; + return [self allSubLabels:YES]; +} + +- (NSArray *)secondarySubLabels { + return [self allSubLabels:NO]; +} + +- (NSArray *)allSubLabels:(BOOL)includePrimary { + return [self.subviews filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"tag >= %i", (includePrimary ? 700 : 701)]]; } #pragma mark - diff --git a/MarqueeLabelDemo/Classes/MarqueeLabelDemoViewController.h b/MarqueeLabelDemo/Classes/MarqueeLabelDemoViewController.h index 186be79d..a4983d82 100644 --- a/MarqueeLabelDemo/Classes/MarqueeLabelDemoViewController.h +++ b/MarqueeLabelDemo/Classes/MarqueeLabelDemoViewController.h @@ -38,6 +38,7 @@ @property (nonatomic, weak) IBOutlet MarqueeLabel *demoLabel3; @property (nonatomic, weak) IBOutlet MarqueeLabel *demoLabel4; @property (nonatomic, weak) IBOutlet MarqueeLabel *demoLabel5; +@property (nonatomic, weak) IBOutlet MarqueeLabel *demoLabel6; @property (nonatomic, weak) IBOutlet UISwitch *labelizeSwitch; @property (nonatomic, weak) IBOutlet UISwitch *holdLabelsSwitch; diff --git a/MarqueeLabelDemo/Classes/MarqueeLabelDemoViewController.m b/MarqueeLabelDemo/Classes/MarqueeLabelDemoViewController.m index ce3b46a1..e9cd1291 100644 --- a/MarqueeLabelDemo/Classes/MarqueeLabelDemoViewController.m +++ b/MarqueeLabelDemo/Classes/MarqueeLabelDemoViewController.m @@ -38,17 +38,18 @@ - (void)viewDidLoad { [super viewDidLoad]; // Continuous Type + self.demoLabel1.tag = 101; self.demoLabel1.marqueeType = MLContinuous; self.demoLabel1.scrollDuration = 15.0; self.demoLabel1.animationCurve = UIViewAnimationOptionCurveEaseInOut; self.demoLabel1.fadeLength = 10.0f; self.demoLabel1.leadingBuffer = 30.0f; self.demoLabel1.trailingBuffer = 20.0f; - self.demoLabel1.tag = 101; // Text string for this label is set via Interface Builder! // Reverse Continuous Type, with attributed string + self.demoLabel2.tag = 201; self.demoLabel2.marqueeType = MLContinuousReverse; self.demoLabel2.scrollDuration = 8.0; self.demoLabel2.fadeLength = 15.0f; @@ -63,6 +64,7 @@ - (void)viewDidLoad { // Left/right example, with rate usage + self.demoLabel3.tag = 301; self.demoLabel3.marqueeType = MLLeftRight; self.demoLabel3.rate = 30.0f; self.demoLabel3.fadeLength = 10.0f; @@ -70,17 +72,17 @@ - (void)viewDidLoad { self.demoLabel3.trailingBuffer = 20.0f; self.demoLabel3.textAlignment = NSTextAlignmentCenter; self.demoLabel3.text = @"This is another long label that scrolls at a specific rate, rather than scrolling its length in a specific time window!"; - self.demoLabel3.tag = 102; // Right/left example, with tap to scroll + self.demoLabel4.tag = 401; self.demoLabel4.marqueeType = MLRightLeft; self.demoLabel4.tapToScroll = YES; self.demoLabel4.trailingBuffer = 20.0f; self.demoLabel4.text = @"This label will not scroll until tapped, and then it performs its scroll cycle only once. Tap me!"; - // Continuous, with tap to pause + self.demoLabel5.tag = 501; self.demoLabel5.marqueeType = MLContinuous; self.demoLabel5.scrollDuration = 10.0f; self.demoLabel5.fadeLength = 10.0f; @@ -92,6 +94,20 @@ - (void)viewDidLoad { tapRecognizer.numberOfTapsRequired = 1; tapRecognizer.numberOfTouchesRequired = 1; [self.demoLabel5 addGestureRecognizer:tapRecognizer]; + + // Continuous, with attributed text + self.demoLabel6.tag = 601; + self.demoLabel6.marqueeType = MLContinuous; + self.demoLabel6.scrollDuration = 15.0f; + self.demoLabel6.fadeLength = 10.0f; + self.demoLabel6.trailingBuffer = 30.0f; + + attributedString = [[NSMutableAttributedString alloc] initWithString:@"This is a long, attributed string, that's set up to loop in a continuous fashion!"]; + [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.123 green:0.331 blue:0.657 alpha:1.000] range:NSMakeRange(0,34)]; + [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.657 green:0.096 blue:0.088 alpha:1.000] range:NSMakeRange(34, attributedString.length - 34)]; + [attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Light" size:18.0f] range:NSMakeRange(0, 16)]; + [attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Light" size:18.0f] range:NSMakeRange(33, attributedString.length - 33)]; + self.demoLabel6.attributedText = attributedString; } - (IBAction)changeLabelTexts:(id)sender { @@ -108,6 +124,13 @@ - (IBAction)changeLabelTexts:(id)sender { [attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Light" size:18.0f] range:NSMakeRange(19, attributedString.length - 19)]; self.demoLabel2.attributedText = attributedString; + attributedString = [[NSMutableAttributedString alloc] initWithString:@"This is a different, longer, attributed string, that's set up to loop in a continuous fashion!"]; + [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.657 green:0.078 blue:0.067 alpha:1.000] range:NSMakeRange(0,attributedString.length)]; + [attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Light" size:18.0f] range:NSMakeRange(0, 16)]; + [attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Light" size:18.0f] range:NSMakeRange(33, attributedString.length - 33)]; + [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.123 green:0.331 blue:0.657 alpha:1.000] range:NSMakeRange(33, attributedString.length - 33)]; + self.demoLabel6.attributedText = attributedString; + self.demoLabel1.tag = 102; } else { self.demoLabel1.text = @"This is a test of MarqueeLabel - the text is long enough that it needs to scroll to see the whole thing."; @@ -120,6 +143,12 @@ - (IBAction)changeLabelTexts:(id)sender { [attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Light" size:18.0f] range:NSMakeRange(21, attributedString.length - 21)]; self.demoLabel2.attributedText = attributedString; + attributedString = [[NSMutableAttributedString alloc] initWithString:@"This is a long, attributed string, that's set up to loop in a continuous fashion!"]; + [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.123 green:0.331 blue:0.657 alpha:1.000] range:NSMakeRange(0,attributedString.length)]; + [attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Light" size:18.0f] range:NSMakeRange(0, 16)]; + [attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Light" size:18.0f] range:NSMakeRange(33, attributedString.length - 33)]; + self.demoLabel6.attributedText = attributedString; + self.demoLabel1.tag = 101; } } diff --git a/MarqueeLabelDemo/MarqueeLabel.storyboard b/MarqueeLabelDemo/MarqueeLabel.storyboard index 49c1ca0e..50cf50dd 100644 --- a/MarqueeLabelDemo/MarqueeLabel.storyboard +++ b/MarqueeLabelDemo/MarqueeLabel.storyboard @@ -1,8 +1,9 @@ - + - + + @@ -42,7 +43,7 @@ - + - + - + + + + + @@ -194,15 +227,17 @@ - - + + - + - + + + @@ -213,7 +248,7 @@ - + @@ -224,10 +259,12 @@ + + @@ -239,6 +276,7 @@ +