LCActionSheetCell.m 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. self.clipsToBounds = YES;
  39. self.backgroundColor = [UIColor clearColor];
  40. UIView *highlightedView = [[UIView alloc] init];
  41. highlightedView.backgroundColor = self.cellSeparatorColor;
  42. highlightedView.clipsToBounds = YES;
  43. highlightedView.hidden = YES;
  44. [self.contentView addSubview:highlightedView];
  45. self.highlightedView = highlightedView;
  46. [highlightedView mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.edges.equalTo(self.contentView);
  48. }];
  49. UILabel *titleLabel = [[UILabel alloc] init];
  50. titleLabel.textAlignment = NSTextAlignmentCenter;
  51. titleLabel.adjustsFontSizeToFitWidth = YES;
  52. [self.contentView addSubview:titleLabel];
  53. self.titleLabel = titleLabel;
  54. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(0, 10.0f, 0, 10.0f));
  56. }];
  57. UIView *lineView = [[UIView alloc] init];
  58. lineView.backgroundColor = self.cellSeparatorColor;
  59. lineView.contentMode = UIViewContentModeBottom;
  60. lineView.clipsToBounds = YES;
  61. [self.contentView addSubview:lineView];
  62. self.lineView = lineView;
  63. [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.left.right.bottom.equalTo(self.contentView);
  65. make.height.equalTo(@0.5f);
  66. }];
  67. }
  68. return self;
  69. }
  70. - (void)setCellSeparatorColor:(UIColor *)cellSeparatorColor {
  71. _cellSeparatorColor = cellSeparatorColor;
  72. self.highlightedView.backgroundColor = cellSeparatorColor;
  73. self.lineView.backgroundColor = cellSeparatorColor;
  74. }
  75. - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
  76. if (self.tag == LC_ACTION_SHEET_CELL_HIDDE_LINE_TAG) {
  77. self.lineView.hidden = YES;
  78. } else {
  79. self.lineView.hidden = highlighted;
  80. }
  81. self.highlightedView.hidden = !highlighted;
  82. }
  83. @end