Skip to content

Commit 77d8be3

Browse files
committed
Added an attributes for text in range
1 parent 01c1861 commit 77d8be3

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

MZTimerLabel/MZTimerLabel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ typedef enum{
7777
/*Used for replace text in range */
7878
@property (nonatomic, assign) NSRange textRange;
7979

80+
@property (nonatomic, strong) NSDictionary *attributedDictionaryForTextInRange;
81+
8082
/*Type to choose from stopwatch or timer*/
8183
@property (assign) MZTimerLabelType timerType;
8284

MZTimerLabel/MZTimerLabel.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,19 @@ -(void)updateLabel{
365365
//0.4.7 added---endb//
366366
}else{
367367
if(self.textRange.length > 0){
368-
NSString* labelText = [self.text stringByReplacingCharactersInRange:self.textRange withString:[self.dateFormatter stringFromDate:timeToShow]];
369-
self.timeLabel.text = labelText;
368+
if(self.attributedDictionaryForTextInRange){
369+
370+
NSAttributedString *attrTextInRange = [[NSAttributedString alloc] initWithString:[self.dateFormatter stringFromDate:timeToShow] attributes:self.attributedDictionaryForTextInRange];
371+
372+
NSMutableAttributedString *attributedString;
373+
attributedString = [[NSMutableAttributedString alloc]initWithString:self.text];
374+
[attributedString replaceCharactersInRange:self.textRange withAttributedString:attrTextInRange];
375+
self.timeLabel.attributedText = attributedString;
376+
377+
} else {
378+
NSString *labelText = [self.text stringByReplacingCharactersInRange:self.textRange withString:[self.dateFormatter stringFromDate:timeToShow]];
379+
self.timeLabel.text = labelText;
380+
}
370381
} else {
371382
self.timeLabel.text = [self.dateFormatter stringFromDate:timeToShow];
372383
}

0 commit comments

Comments
 (0)