Skip to content

Commit

Permalink
Merge branch 'kmckinley-feature/Issue_98_AttributedText_color_get_ove…
Browse files Browse the repository at this point in the history
…rridden'
  • Loading branch information
cbpowell committed Apr 18, 2015
2 parents 91cfbad + 87cb425 commit 7739e2f
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 29 deletions.
16 changes: 14 additions & 2 deletions MarqueeLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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 -
Expand Down
1 change: 1 addition & 0 deletions MarqueeLabelDemo/Classes/MarqueeLabelDemoViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
35 changes: 32 additions & 3 deletions MarqueeLabelDemo/Classes/MarqueeLabelDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -63,24 +64,25 @@ - (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;
self.demoLabel3.leadingBuffer = 30.0f;
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;
Expand All @@ -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 {
Expand All @@ -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.";
Expand All @@ -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;
}
}
Expand Down
Loading

0 comments on commit 7739e2f

Please sign in to comment.