RootModeCell.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // RootModeCell.m
  3. // RA Image
  4. //
  5. // Created by Jack on 2017/5/2.
  6. // Copyright © 2017年 USAI. All rights reserved.
  7. //
  8. #import "RootModeCell.h"
  9. @interface RootModeCell ()
  10. @property (strong, nonatomic) IBOutlet UILabel *modeLabel;
  11. @end
  12. @implementation RootModeCell
  13. - (void)awakeFromNib {
  14. [super awakeFromNib];
  15. // Initialization code
  16. }
  17. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  18. [super setSelected:selected animated:animated];
  19. // Configure the view for the selected state
  20. }
  21. - (void)setMode:(NSString *)mode {
  22. _mode = mode;
  23. self.modeLabel.text = mode;
  24. }
  25. - (void)setEnable:(BOOL)enable {
  26. _enable = enable;
  27. self.modeLabel.enabled = enable;
  28. }
  29. - (void)setMode:(NSString *)mode desc:(NSString *)desc {
  30. _mode = mode;
  31. _desc = desc;
  32. // _desc = @"dfhajkdhfkajhdklahdfalllllllalalalalaPKOSdididiididdi";
  33. self.modeLabel.attributedText = nil;
  34. self.modeLabel.text = nil;
  35. if (desc == nil || desc.length == 0) {
  36. self.modeLabel.text = mode;
  37. } else if (mode == nil || mode.length == 0){
  38. self.modeLabel.text = mode;
  39. } else {
  40. NSString *str = [NSString stringWithFormat:@"%@ -- %@",_mode,_desc];
  41. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:str];
  42. NSRange redRange = NSMakeRange(_mode.length + 1, str.length - (_mode.length + 1));
  43. NSRange normalRange = NSMakeRange(0, _mode.length);
  44. NSDictionary *redAttrs = @{
  45. NSForegroundColorAttributeName : [UIColor redColor],
  46. NSFontAttributeName : [UIFont systemFontOfSize:15.0f]
  47. };
  48. NSDictionary *normalAttrs = @{
  49. NSForegroundColorAttributeName : [UIColor blackColor],
  50. NSFontAttributeName : [UIFont systemFontOfSize:17.0f]
  51. };
  52. [attrStr addAttributes:redAttrs range:redRange];
  53. [attrStr addAttributes:normalAttrs range:normalRange];
  54. self.modeLabel.attributedText = attrStr;
  55. }
  56. }
  57. @end