UIView+Layout.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // UIView+Layout.m
  3. //
  4. // Created by XM on 18/2/24.
  5. // Copyright © 2018年 XM. All rights reserved.
  6. //
  7. #import "UIView+Layout.h"
  8. //#import "LangTranslator.h"
  9. #import "Header.h"
  10. @implementation UIView (Layout)
  11. - (CGFloat)tz_left {
  12. return self.frame.origin.x;
  13. }
  14. - (void)setTz_left:(CGFloat)x {
  15. CGRect frame = self.frame;
  16. frame.origin.x = x;
  17. self.frame = frame;
  18. }
  19. - (CGFloat)tz_top {
  20. return self.frame.origin.y;
  21. }
  22. - (void)setTz_top:(CGFloat)y {
  23. CGRect frame = self.frame;
  24. frame.origin.y = y;
  25. self.frame = frame;
  26. }
  27. - (CGFloat)tz_right {
  28. return self.frame.origin.x + self.frame.size.width;
  29. }
  30. - (void)setTz_right:(CGFloat)right {
  31. CGRect frame = self.frame;
  32. frame.origin.x = right - frame.size.width;
  33. self.frame = frame;
  34. }
  35. - (CGFloat)tz_bottom {
  36. return self.frame.origin.y + self.frame.size.height;
  37. }
  38. - (void)setTz_bottom:(CGFloat)bottom {
  39. CGRect frame = self.frame;
  40. frame.origin.y = bottom - frame.size.height;
  41. self.frame = frame;
  42. }
  43. - (CGFloat)tz_width {
  44. return self.frame.size.width;
  45. }
  46. - (void)setTz_width:(CGFloat)width {
  47. CGRect frame = self.frame;
  48. frame.size.width = width;
  49. self.frame = frame;
  50. }
  51. - (CGFloat)tz_height {
  52. return self.frame.size.height;
  53. }
  54. - (void)setTz_height:(CGFloat)height {
  55. CGRect frame = self.frame;
  56. frame.size.height = height;
  57. self.frame = frame;
  58. }
  59. - (CGFloat)tz_centerX {
  60. return self.center.x;
  61. }
  62. - (void)setTz_centerX:(CGFloat)centerX {
  63. self.center = CGPointMake(centerX, self.center.y);
  64. }
  65. - (CGFloat)tz_centerY {
  66. return self.center.y;
  67. }
  68. - (void)setTz_centerY:(CGFloat)centerY {
  69. self.center = CGPointMake(self.center.x, centerY);
  70. }
  71. - (CGPoint)tz_origin {
  72. return self.frame.origin;
  73. }
  74. - (void)setTz_origin:(CGPoint)origin {
  75. CGRect frame = self.frame;
  76. frame.origin = origin;
  77. self.frame = frame;
  78. }
  79. - (CGSize)tz_size {
  80. return self.frame.size;
  81. }
  82. - (void)setTz_size:(CGSize)size {
  83. CGRect frame = self.frame;
  84. frame.size = size;
  85. self.frame = frame;
  86. }
  87. + (void)showOscillatoryAnimationWithLayer:(CALayer *)layer type:(TZOscillatoryAnimationType)type{
  88. NSNumber *animationScale1 = type == TZOscillatoryAnimationToBigger ? @(1.15) : @(0.5);
  89. NSNumber *animationScale2 = type == TZOscillatoryAnimationToBigger ? @(0.92) : @(1.15);
  90. [UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{
  91. [layer setValue:animationScale1 forKeyPath:@"transform.scale"];
  92. } completion:^(BOOL finished) {
  93. [UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{
  94. [layer setValue:animationScale2 forKeyPath:@"transform.scale"];
  95. } completion:^(BOOL finished) {
  96. [UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{
  97. [layer setValue:@(1.0) forKeyPath:@"transform.scale"];
  98. } completion:nil];
  99. }];
  100. }];
  101. }
  102. + (UIAlertView *) allocPwdInputAlert:(NSString *)msg delegate:(nullable id)delegate{
  103. UIAlertView * alert = [[UIAlertView alloc]initWithTitle:TS("Invalid_Password") message:msg delegate:delegate cancelButtonTitle:nil otherButtonTitles:TS("Cancel"), TS("OK"), nil];
  104. alert.alertViewStyle = UIAlertViewStyleSecureTextInput;
  105. UITextField *tiptextField = [alert textFieldAtIndex:0];
  106. tiptextField.frame = CGRectMake(0, 0, 200, 10);
  107. tiptextField.secureTextEntry = YES;
  108. tiptextField.borderStyle=UITextBorderStyleNone;
  109. tiptextField.placeholder = TS("Please input password");
  110. tiptextField.layer.borderColor = [UIColor colorWithRed:36/255.0 green:183/255.0 blue:177/255.0 alpha:1].CGColor;
  111. tiptextField.layer.cornerRadius = 5;
  112. return alert;
  113. }
  114. @end