Skip to content

Commit b6b6531

Browse files
committed
Added a textRange property for replacing text in specified range
1 parent cbec232 commit b6b6531

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

MZTimerLabel/MZTimerLabel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ typedef enum{
7474
/*Target label obejct, default self if you do not initWithLabel nor set*/
7575
@property (nonatomic,strong) UILabel *timeLabel;
7676

77+
/*Used for replace text in range */
78+
@property (nonatomic, assign) NSRange textRange;
79+
7780
/*Type to choose from stopwatch or timer*/
7881
@property (assign) MZTimerLabelType timerType;
7982

MZTimerLabel/MZTimerLabel.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,12 @@ -(void)updateLabel{
364364
self.dateFormatter.dateFormat = originalTimeFormat;
365365
//0.4.7 added---endb//
366366
}else{
367-
self.timeLabel.text = [self.dateFormatter stringFromDate:timeToShow];
367+
if(self.textRange.length > 0){
368+
NSString* labelText = [self.text stringByReplacingCharactersInRange:self.textRange withString:[self.dateFormatter stringFromDate:timeToShow]];
369+
self.timeLabel.text = labelText;
370+
} else {
371+
self.timeLabel.text = [self.dateFormatter stringFromDate:timeToShow];
372+
}
368373
}
369374
}
370375

0 commit comments

Comments
 (0)