react-native-navigation的迁移库

RCCCustomTitleView.m 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // RCCTitleView.m
  3. // ReactNativeNavigation
  4. //
  5. // Created by Ran Greenberg on 26/04/2017.
  6. // Copyright © 2017 artal. All rights reserved.
  7. //
  8. #import "RCCCustomTitleView.h"
  9. @interface RCCCustomTitleView ()
  10. @property (nonatomic, strong) UIView *subView;
  11. @property (nonatomic, strong) NSString *subViewAlign;
  12. @end
  13. @implementation RCCCustomTitleView
  14. -(instancetype)initWithFrame:(CGRect)frame subView:(UIView*)subView alignment:(NSString*)alignment {
  15. self = [super initWithFrame:frame];
  16. if (self) {
  17. self.backgroundColor = [UIColor clearColor];
  18. self.subView = subView;
  19. self.subViewAlign = alignment;
  20. subView.frame = self.bounds;
  21. [self addSubview:subView];
  22. }
  23. return self;
  24. }
  25. -(void)layoutSubviews {
  26. [super layoutSubviews];
  27. if ([self.subViewAlign isEqualToString:@"fill"]) {
  28. self.subView.frame = self.bounds;
  29. }
  30. else {
  31. CGFloat superViewWidth = self.superview.frame.size.width;
  32. CGFloat paddingLeftFromCenter = (superViewWidth/2) - self.frame.origin.x;
  33. CGFloat paddingRightFromCenter = self.frame.size.width - paddingLeftFromCenter;;
  34. CGRect reactViewFrame = self.subView.bounds;
  35. CGFloat minPadding = MIN(paddingLeftFromCenter, paddingRightFromCenter);
  36. reactViewFrame.size.width = minPadding*2;
  37. reactViewFrame.origin.x = paddingLeftFromCenter - minPadding;
  38. self.subView.frame = reactViewFrame;
  39. }
  40. }
  41. @end