POBaseStyleTableViewCell.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // POBaseStyleTableViewCell.h
  3. // powerone
  4. //
  5. // Created by kinghai on 2018/8/3.
  6. // Copyright © 2018年 onecloud.ltd. All rights reserved.
  7. //
  8. /** 样式设置文件 */
  9. #import <UIKit/UIKit.h>
  10. #define IconCornerRadius GetUserHead_shape ? 3.0 : AvatarImageViewWidthOrHeight / 2.0 //头像圆角半径
  11. #define CellStyleViewLeftRightMargin 8 //cell的阴影圆角距离左右边距
  12. #define CellStyleViewVerticalMargin 10 //两个阴影圆角cell的距离 或 cell距离顶部
  13. #define StyleButtonHeight 40 //按钮高度
  14. #define StyleButtonCornerRadius 3 //按钮圆角半径
  15. #define StyleButtonWithCellLeftRightMargin 8 //按钮在tableViewCell下面时的左右边距
  16. #define StyleButtonWithCellTopMargin 20 //按钮在tableViewCell下面时的距离上面cell的边距
  17. #define StyleButtonWithoutCellLeftRightMargin 58 //按钮不在tableViewCell下面时的左右边距
  18. #define StyleButtonBorderColorGrey UIColorFromHex(0xd2d2d2) //白色按钮的边框颜色
  19. #define StyleButtonColorWhite UIColorFromHex(0xFBFBFB) //白色按钮
  20. #define StyleButtonColorGreen kAppThemeColor //绿色按钮
  21. #define StyleButtonColorRed kAppRedColor //红色按钮
  22. #define StyleButtonTitleColorBlack kBlackColor_3 //按钮黑色标题
  23. #define StyleButtonTitleColorWhite YHColor(255, 255, 255) //按钮白色标题(不能使用[UIColor whiteColor],会导致CGColorGetNumberOfComponents返回2)
  24. #define StyleButtonTitleColorRed [UIColor redColor] //按钮红色标题
  25. #define AddressListSectionHeaderHeight 20 //通讯录的组的头视图高度
  26. #define SeparatorLineViewHeight 0.8 //分隔线的高度
  27. /** 哪一边无阴影 */
  28. typedef NS_ENUM(NSInteger, PONoShadowSide)
  29. {
  30. PONoShadowSideNone = 1 << 0, //没有边是无阴影的,即四边都有阴影
  31. PONoShadowSideLeft = 1 << 1, //左边无阴影
  32. PONoShadowSideRight = 1 << 2, //右边无阴影
  33. PONoShadowSideTop = 1 << 3, //上边无阴影
  34. PONoShadowSideBottom = 1 << 4, //下边无阴影
  35. PONoShadowSideAll = 1 << 5, //四边都无阴影
  36. };
  37. /** 设置样式所需的数据 */
  38. @interface POCellStyleDataModel : NSObject
  39. /** 圆角半径(0代表无圆角) */
  40. @property (nonatomic, assign) CGFloat cornerRadius;
  41. /** 是否有阴影 */
  42. @property (nonatomic, assign) BOOL showShadow;
  43. /** 阴影颜色 */
  44. @property (nonatomic, strong) UIColor *shadowColor;
  45. /** 阴影不透明度 */
  46. @property (nonatomic, assign) CGFloat shadowOpacity;
  47. /** 阴影偏移 */
  48. @property (nonatomic, assign) CGSize shadowOffset;
  49. /** 阴影半径 */
  50. @property (nonatomic, assign) CGFloat shadowRadius;
  51. /** 要设置圆角的位置(当corners不是全部四个圆角时,必须设置styleViewSize,否则显示错误) */
  52. @property (nonatomic, assign) UIRectCorner corners;
  53. /** 圆角背景视图的高宽(当corners不是全部四个圆角时,必须设置这个属性,否则显示错误) */
  54. @property (nonatomic, assign) CGSize styleViewSize;
  55. /** 没有阴影的边 */
  56. @property (nonatomic, assign) PONoShadowSide noShadowSide;
  57. /** 背景卡片距离cell的边距 */
  58. @property (nonatomic, assign) UIEdgeInsets edgeInsets;
  59. /** cell背景颜色 */
  60. @property (nonatomic, strong) UIColor *cellBackgroundColor;
  61. @end
  62. /** cell的特殊样式背景视图,用init初始化,然后调用setupViewWithStyleModel才能设置特定样式 */
  63. @interface POCellStyleBackgroundView : UIView
  64. /** 风格model*/
  65. @property (nonatomic, strong) POCellStyleDataModel *styleModel;
  66. @end
  67. /** 具有卡片样式的cell
  68. 使用方法:
  69. ①直接继承POBaseStyleTableViewCell,使用默认的styleBackgroundView(在用initWithStyle:reuseIdentifier:初始化cell时创建),设置了四个圆角+距离cell边距为(5,8,5,8)+阴影;
  70. ②如果需要修改默认的styleBackgroundView,可以在子类cell的initWithStyle:reuseIdentifier:方法中设置styleModel进行修改,适用于子类cell的所有实例都是这个样式;如果子类cell的不同实例需要不同的styleBackgroundView(比如section的第一个cell只有上部分圆角、最后一个cell只有下部分圆角、中间cell无圆角),则在cellForRowAtIndexPath中为每个cell设置不同的styleModel。
  71. 注意:
  72. 子类cell的backgroundColor需要是clearColor;子类cell的子视图不能遮盖styleBackgroundView;reloadRowsAtIndexPaths如果数组有两个元素会导致阴影闪烁,只能一个一个reload。
  73. */
  74. @interface POBaseStyleTableViewCell : UITableViewCell
  75. /** 具有样式的cell背景视图,比如有圆角阴影(由于_styleBackgroundView在最底层,所以它的子视图无法响应手势,需要响应手势的子视图添加到self或self.contentView) */
  76. @property (nonatomic, strong, readonly) POCellStyleBackgroundView *styleBackgroundView;
  77. /** 设置cell背景样式所需的数据(如果styleModel=nil或者styleModel的某个属性值为空,则使用默认值) */
  78. @property (nonatomic, strong) POCellStyleDataModel *styleModel;
  79. @end