KNView.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // KNView.m
  3. // OneCable
  4. //
  5. // Created by Jason Lee on 1/27/16.
  6. // Copyright © 2016 ntels. All rights reserved.
  7. //
  8. #import "KNView.h"
  9. @interface KNView () {
  10. BOOL _isNotFirstLoading;
  11. }
  12. @end
  13. @implementation KNView
  14. - (void)drawRect:(CGRect)rect {
  15. [super drawRect:rect];
  16. if (!_isNotFirstLoading) {
  17. _isNotFirstLoading = YES;
  18. for (NSLayoutConstraint *constraint in self.constraints) {
  19. // NSLog(@"%s\n %@", __PRETTY_FUNCTION__, constraint);
  20. if (constraint.firstAttribute == NSLayoutAttributeLeading || constraint.firstAttribute == NSLayoutAttributeTrailing) {
  21. if ([constraint.firstItem isEqual:self] || [constraint.secondItem isEqual:self]) {
  22. CGFloat constant = constraint.constant;
  23. if (constraint.constant == 10.0f || constraint.constant == 12.0f || constraint.constant == 15.0f || constraint.constant == 27.0f) {
  24. if (IPHONE_WIDTH == 414.0f) {//아이폰 6p일 경우,
  25. constant = constant + 10.0f;
  26. } else if (IPHONE_WIDTH == 375.0f) {//아이폰 6일경우
  27. constant = constant + 5.0f;
  28. }
  29. }
  30. constraint.constant = constant;
  31. }
  32. }
  33. }
  34. }
  35. }
  36. @end
  37. @interface KNView2 () {
  38. BOOL _isNotFirstLoading;
  39. }
  40. @end
  41. @implementation KNView2
  42. - (void)drawRect:(CGRect)rect {
  43. [super drawRect:rect];
  44. if (!_isNotFirstLoading) {
  45. _isNotFirstLoading = YES;
  46. for (NSLayoutConstraint *constraint in self.constraints) {
  47. // NSLog(@"%s\n %@", __PRETTY_FUNCTION__, constraint);
  48. if (constraint.firstAttribute == NSLayoutAttributeLeading || constraint.firstAttribute == NSLayoutAttributeTrailing) {
  49. if ([constraint.firstItem isEqual:self] || [constraint.secondItem isEqual:self]) {
  50. CGFloat constant = constraint.constant;
  51. if (constraint.constant == 10.0f || constraint.constant == 12.0f || constraint.constant == 15.0f || constraint.constant == 27.0f) {
  52. if (IPHONE_WIDTH == 414.0f) {//아이폰 6p일 경우,
  53. constant = constant + 20.0f;
  54. } else if (IPHONE_WIDTH == 375.0f) {//아이폰 6일경우
  55. constant = constant + 10.0f;
  56. }
  57. }
  58. constraint.constant = constant;
  59. }
  60. }
  61. }
  62. }
  63. }
  64. @end