口袋优选

UIView+ScottAutoLayout.h 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // UIView+ScottAutoLayout.h
  3. // QQLive
  4. //
  5. // Created by Scott_Mr on 2016/12/1.
  6. // Copyright © 2016年 Scott. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. @interface UIView (ScottAutoLayout)
  10. /**
  11. view到父视图的边距约束
  12. @param view 需要添加约束的view
  13. @param edgeInset 边距
  14. */
  15. - (void)scott_addConstraintToView:(UIView *)view edgeInset:(UIEdgeInsets)edgeInset;
  16. /**
  17. 给view添加四边约束
  18. @param view 需要添加约束的view
  19. @param topView 顶部参考视图
  20. @param leftView 左边参考视图
  21. @param bottomView 底部参考视图
  22. @param rightView 右边参考视图
  23. @param edgeInset 边距
  24. */
  25. - (void)scott_addConstraintWithView:(UIView *)view topView:(UIView *)topView leftView:(UIView *)leftView
  26. bottomView:(UIView *)bottomView rightView:(UIView *)rightView edgeInset:(UIEdgeInsets)edgeInset;
  27. /**
  28. leftView右边到rightView左边的约束
  29. @param leftView 需要添加约束的view
  30. @param rightView 参考view
  31. @param constant 约束距离
  32. @return 约束
  33. */
  34. - (NSLayoutConstraint *)scott_addConstraintWithLeftView:(UIView *)leftView toRightView:(UIView *)rightView constant:(CGFloat)constant;
  35. /**
  36. topView底部到bottomView顶部的约束
  37. @param topView 需要添加约束的view
  38. @param bottomView 参考view
  39. @param constant 约束距离
  40. @return 约束
  41. */
  42. - (NSLayoutConstraint *)scott_addConstraintWithTopView:(UIView *)topView toBottomView:(UIView *)bottomView constant:(CGFloat)constant;
  43. /**
  44. 固定view的宽高
  45. @param width 宽
  46. @param height 高
  47. */
  48. - (void)scott_addConstraintWidth:(CGFloat)width height:(CGFloat)height;
  49. /**
  50. view和wView等宽,和hView等高
  51. @param view 需要添加约束的view
  52. @param wView 宽度参考view
  53. @param hView 高度参考view
  54. */
  55. - (void)scott_addConstraintEqualWithView:(UIView *)view widthToView:(UIView *)wView heightToView:(UIView *)hView;
  56. /**
  57. yView的中点y坐标与父视图中点y坐标的约束
  58. @param yView 需要添加约束的view
  59. @param constant 约束距离
  60. @return 约束
  61. */
  62. - (NSLayoutConstraint *)scott_addConstraintCenterYToView:(UIView *)yView constant:(CGFloat)constant;
  63. /**
  64. xView的中点x坐标与父视图中点x坐标的约束
  65. @param xView 需要添加约束的view
  66. @param constant 约束距离
  67. @return 约束
  68. */
  69. - (NSLayoutConstraint *)scott_addConstraintCenterXToView:(UIView *)xView constant:(CGFloat)constant;
  70. /**
  71. 移除view的某个约束
  72. @param attr 某个约束
  73. */
  74. - (void)scott_removeConstraintWithAttribte:(NSLayoutAttribute)attr;
  75. /**
  76. 移除指定某个子view的某个约束
  77. @param view 子view
  78. @param attr 某个约束
  79. */
  80. - (void)scott_removeConstraintWithView:(UIView *)view attribute:(NSLayoutAttribute)attr;
  81. /**
  82. 移除所有的约束
  83. */
  84. - (void)scott_removeAllConstraints;
  85. @end