将该头文件 加入到 PCH 中即可;

    1. //
    2. // InlineMethod.h
    3. // FileTransfer
    4. //
    5. // Created by HMC on 16/9/5.
    6. // Copyright © 2016年 SKing. All rights reserved.
    7. //
    8. #ifndef InlineMethod_h
    9. #define InlineMethod_h
    10. #import <UIKit/UIKit.h>
    11. /**
    12. * 设置宽度
    13. *
    14. * @param view 设置的对象 view
    15. * @param width 宽度
    16. *
    17. * @return nil
    18. */
    19. static inline void setWidth(UIView * view, CGFloat width){
    20. CGRect frame = view.frame;
    21. frame.size.width = width;
    22. view.frame = frame;
    23. }
    24. /**
    25. * 获取宽度
    26. *
    27. * @param view 设置的对象 view
    28. *
    29. * @return 宽度
    30. */
    31. static inline CGFloat getWidth(UIView * view){
    32. return view.frame.size.width;
    33. }
    34. /**
    35. * 设置高度
    36. *
    37. * @param view 设置的对象 view
    38. * @param width 高度
    39. *
    40. * @return nil
    41. */
    42. static inline void setHeight(UIView * view, CGFloat height){
    43. CGRect frame = view.frame;
    44. frame.size.height = height;
    45. view.frame = frame;
    46. }
    47. /**
    48. * 获取高度
    49. *
    50. * @param view 设置的对象 view
    51. *
    52. * @return 高度
    53. */
    54. static inline CGFloat getHeight(UIView * view){
    55. return view.frame.size.height;
    56. }
    57. /**
    58. * 缩小放大的帧动画
    59. *
    60. * @return 返回帧动画
    61. */
    62. static inline CAKeyframeAnimation * caKeyframeAnimation (){
    63. CAKeyframeAnimation * keyAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    64. keyAnimation.duration = 0.4;
    65. keyAnimation.removedOnCompletion = YES;
    66. keyAnimation.fillMode = kCAFillModeForwards;
    67. //layer 动画的轨迹点
    68. keyAnimation.values = @[[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.5, 0.5, 1.0)],
    69. [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.3, 1.3, 1.0)],
    70. [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
    71. return keyAnimation;
    72. }
    73. /**
    74. * 获取宽高
    75. *
    76. * @return 宽高
    77. */
    78. #define SCREENWIDTH [UIScreen mainScreen].bounds.size.width
    79. #define SCREENHEIGHT [UIScreen mainScreen].bounds.size.height
    80. /**
    81. * 设置颜色
    82. *
    83. * @param r 红
    84. * @param g 绿
    85. * @param b 蓝
    86. * @param a 透明度
    87. *
    88. * @return UIColor
    89. */
    90. #define setRGBColor(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
    91. /**
    92. * 定义弱引用 self
    93. *
    94. * @param self 本身
    95. *
    96. * @return 弱 self
    97. */
    98. #define weaklySelf(self) __weak typeof(self) weakSelf = self
    99. #define stronglySelf(self) __strong typeof(self) strongSelf = self
    100. /**
    101. * 获取 class 所在的 bundle
    102. *
    103. * @return 返回 bundle
    104. */
    105. #define getBundle [NSBundle bundleForClass:[self class]]
    106. // 图片路径
    107. #define getPicName(picName) [@"图片封装的bundle名字(*****.bundle)" stringByAppendingPathComponent: picName]
    108. #define getAllFrameworkOfPicName(picName) [@"全路径" stringByAppendingPathComponent: picName]
    109. #endif /* InlineMethod_h */