You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2KB

  1. @interface UIDateLabel : UILabel
  2. @property (nonatomic, strong) NSDate *date;
  3. @end
  4. @interface MPRecentsTableViewCell
  5. @property (nonatomic, strong) UIDateLabel *callerDateLabel;
  6. @end
  7. static bool is24h;
  8. %hook MPRecentsTableViewCell
  9. -(void)layoutSubviews{
  10. %orig;
  11. if(![self.callerDateLabel.text containsString:@":"]){
  12. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  13. if(is24h){
  14. [dateFormatter setDateFormat:@"\nHH:mm"];
  15. }else{
  16. [dateFormatter setDateFormat:@"\nh:mm a"];
  17. }
  18. self.callerDateLabel.textAlignment = 2;
  19. self.callerDateLabel.numberOfLines = 2;
  20. self.callerDateLabel.text = [self.callerDateLabel.text stringByAppendingString:[dateFormatter stringFromDate:self.callerDateLabel.date]];
  21. }
  22. }
  23. %end
  24. %ctor{
  25. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  26. [formatter setLocale:[NSLocale currentLocale]];
  27. [formatter setDateStyle:NSDateFormatterNoStyle];
  28. [formatter setTimeStyle:NSDateFormatterShortStyle];
  29. NSString *dateString = [formatter stringFromDate:[NSDate date]];
  30. NSRange amRange = [dateString rangeOfString:[formatter AMSymbol]];
  31. NSRange pmRange = [dateString rangeOfString:[formatter PMSymbol]];
  32. is24h = (amRange.location == NSNotFound && pmRange.location == NSNotFound);
  33. }