LCActionSheetCell.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // LCActionSheetCell.m
  3. // LCActionSheet
  4. //
  5. // Created by Leo on 2016/7/15.
  6. //
  7. // Copyright (c) 2015-2017 Leo <leodaxia@gmail.com>
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in all
  17. // copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  25. // SOFTWARE.
  26. #import "LCActionSheetCell.h"
  27. #import "Masonry.h"
  28. #import "LCActionSheetConfig.h"
  29. @interface LCActionSheetCell ()
  30. /**
  31. * Highlighted View.
  32. */
  33. @property (nonatomic, weak) UIView *highlightedView;
  34. @end
  35. @implementation LCActionSheetCell
  36. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  37. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  38. @weakify(self)
  39. self.clipsToBounds = YES;
  40. self.backgroundColor = [UIColor clearColor];
  41. UIView *highlightedView = [[UIView alloc] init];
  42. highlightedView.backgroundColor = self.cellSeparatorColor;
  43. highlightedView.clipsToBounds = YES;
  44. highlightedView.hidden = YES;
  45. [self.contentView addSubview:highlightedView];
  46. self.highlightedView = highlightedView;
  47. [highlightedView mas_makeConstraints:^(MASConstraintMaker *make) {
  48. @strongify(self)
  49. make.edges.equalTo(self.contentView);
  50. }];
  51. UILabel *titleLabel = [[UILabel alloc] init];
  52. titleLabel.textAlignment = NSTextAlignmentCenter;
  53. titleLabel.adjustsFontSizeToFitWidth = YES;
  54. [self.contentView addSubview:titleLabel];
  55. self.titleLabel = titleLabel;
  56. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  57. @strongify(self)
  58. make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(0, 10.0f, 0, 10.0f));
  59. }];
  60. UIView *lineView = [[UIView alloc] init];
  61. lineView.backgroundColor = self.cellSeparatorColor;
  62. lineView.contentMode = UIViewContentModeBottom;
  63. lineView.clipsToBounds = YES;
  64. [self.contentView addSubview:lineView];
  65. self.lineView = lineView;
  66. [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  67. @strongify(self)
  68. make.left.right.bottom.equalTo(self.contentView);
  69. make.height.equalTo(@0.5f);
  70. }];
  71. }
  72. return self;
  73. }
  74. - (void)setCellSeparatorColor:(UIColor *)cellSeparatorColor {
  75. _cellSeparatorColor = cellSeparatorColor;
  76. self.highlightedView.backgroundColor = cellSeparatorColor;
  77. self.lineView.backgroundColor = cellSeparatorColor;
  78. }
  79. - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
  80. if (self.tag == LC_ACTION_SHEET_CELL_HIDDE_LINE_TAG) {
  81. self.lineView.hidden = YES;
  82. } else {
  83. self.lineView.hidden = highlighted;
  84. }
  85. self.highlightedView.hidden = !highlighted;
  86. }
  87. @end