SCIndexViewConfiguration.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #import "SCIndexViewConfiguration.h"
  2. const NSUInteger SCIndexViewInvalidSection = NSUIntegerMax - 1;
  3. const NSInteger SCIndexViewSearchSection = -1;
  4. static inline UIColor *SCGetColor(CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha)
  5. {
  6. return [UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:alpha];
  7. }
  8. @interface SCIndexViewConfiguration ()
  9. @property (nonatomic, assign) SCIndexViewStyle indexViewStyle; // 索引元素之间间隔距离
  10. @end
  11. @implementation SCIndexViewConfiguration
  12. @synthesize indexViewStyle = _indexViewStyle;
  13. + (instancetype)configuration
  14. {
  15. return [self configurationWithIndexViewStyle:SCIndexViewStyleDefault];
  16. }
  17. + (instancetype)configurationWithIndexViewStyle:(SCIndexViewStyle)indexViewStyle
  18. {
  19. UIColor *indicatorBackgroundColor, *indicatorTextColor;
  20. UIFont *indicatorTextFont;
  21. CGFloat indicatorHeight;
  22. switch (indexViewStyle) {
  23. case SCIndexViewStyleDefault:
  24. {
  25. indicatorBackgroundColor = SCGetColor(200, 200, 200, 1);
  26. indicatorTextColor = [UIColor whiteColor];
  27. indicatorTextFont = [UIFont systemFontOfSize:38];
  28. indicatorHeight = 50;
  29. }
  30. break;
  31. case SCIndexViewStyleCenterToast:
  32. {
  33. indicatorBackgroundColor = SCGetColor(200, 200, 200, 0.8);
  34. indicatorTextColor = [UIColor whiteColor];
  35. indicatorTextFont = [UIFont systemFontOfSize:60];
  36. indicatorHeight = 120;
  37. }
  38. break;
  39. default:
  40. return nil;
  41. break;
  42. }
  43. return [self configurationWithIndexViewStyle:indexViewStyle
  44. indicatorBackgroundColor:indicatorBackgroundColor
  45. indicatorTextColor:indicatorTextColor
  46. indicatorTextFont:indicatorTextFont
  47. indicatorHeight:indicatorHeight
  48. indicatorRightMargin:40
  49. indicatorCornerRadius:10
  50. indexItemBackgroundColor:[UIColor clearColor]
  51. indexItemTextColor:[UIColor darkGrayColor]
  52. indexItemTextFont:[UIFont fontWithName:@"Helvetica" size:12]
  53. indexItemSelectedBackgroundColor:SCGetColor(40, 170, 40, 1)
  54. indexItemSelectedTextColor:[UIColor whiteColor]
  55. indexItemSelectedTextFont:[UIFont fontWithName:@"Helvetica" size:12]
  56. indexItemHeight:15
  57. indexItemRightMargin:5
  58. indexItemsSpace:0];
  59. }
  60. + (instancetype)configurationWithIndexViewStyle:(SCIndexViewStyle)indexViewStyle
  61. indicatorBackgroundColor:(UIColor *)indicatorBackgroundColor
  62. indicatorTextColor:(UIColor *)indicatorTextColor
  63. indicatorTextFont:(UIFont *)indicatorTextFont
  64. indicatorHeight:(CGFloat)indicatorHeight
  65. indicatorRightMargin:(CGFloat)indicatorRightMargin
  66. indicatorCornerRadius:(CGFloat)indicatorCornerRadius
  67. indexItemBackgroundColor:(UIColor *)indexItemBackgroundColor
  68. indexItemTextColor:(UIColor *)indexItemTextColor
  69. indexItemTextFont:(UIFont *)indexItemTextFont
  70. indexItemSelectedBackgroundColor:(UIColor *)indexItemSelectedBackgroundColor
  71. indexItemSelectedTextColor:(UIColor *)indexItemSelectedTextColor
  72. indexItemSelectedTextFont:(UIFont *)indexItemSelectedTextFont
  73. indexItemHeight:(CGFloat)indexItemHeight
  74. indexItemRightMargin:(CGFloat)indexItemRightMargin
  75. indexItemsSpace:(CGFloat)indexItemsSpace
  76. {
  77. SCIndexViewConfiguration *configuration = [self new];
  78. if (!configuration) return nil;
  79. configuration.indexViewStyle = indexViewStyle;
  80. configuration.indicatorBackgroundColor = indicatorBackgroundColor;
  81. configuration.indicatorTextColor = indicatorTextColor;
  82. configuration.indicatorTextFont = indicatorTextFont;
  83. configuration.indicatorHeight = indicatorHeight;
  84. configuration.indicatorRightMargin = indicatorRightMargin;
  85. configuration.indicatorCornerRadius = indicatorCornerRadius;
  86. configuration.indexItemBackgroundColor = indexItemBackgroundColor;
  87. configuration.indexItemTextColor = indexItemTextColor;
  88. configuration.indexItemTextFont = indexItemTextFont;
  89. configuration.indexItemSelectedBackgroundColor = indexItemSelectedBackgroundColor;
  90. configuration.indexItemSelectedTextColor = indexItemSelectedTextColor;
  91. configuration.indexItemSelectedTextFont = indexItemSelectedTextFont;
  92. configuration.indexItemHeight = indexItemHeight;
  93. configuration.indexItemRightMargin = indexItemRightMargin;
  94. configuration.indexItemsSpace = indexItemsSpace;
  95. return configuration;
  96. }
  97. @end