react-native-navigation的迁移库

RNNCustomTitleView.m 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #import "RNNCustomTitleView.h"
  2. @interface RNNCustomTitleView ()
  3. @property (nonatomic, strong) UIView *subView;
  4. @property (nonatomic, strong) NSString *subViewAlign;
  5. @end
  6. @implementation RNNCustomTitleView
  7. -(instancetype)initWithFrame:(CGRect)frame subView:(UIView*)subView alignment:(NSString*)alignment {
  8. self = [super initWithFrame:frame];
  9. if (self) {
  10. self.backgroundColor = [UIColor clearColor];
  11. self.subView = subView;
  12. self.subViewAlign = alignment;
  13. subView.frame = self.bounds;
  14. [self addSubview:subView];
  15. }
  16. return self;
  17. }
  18. -(void)layoutSubviews {
  19. [super layoutSubviews];
  20. if ([self.subViewAlign isEqualToString:@"fill"]) {
  21. self.subView.frame = self.bounds;
  22. }
  23. else {
  24. CGFloat superViewWidth = self.superview.frame.size.width;
  25. CGFloat paddingLeftFromCenter = (superViewWidth/2) - self.frame.origin.x;
  26. CGFloat paddingRightFromCenter = self.frame.size.width - paddingLeftFromCenter;;
  27. CGRect reactViewFrame = self.subView.bounds;
  28. CGFloat minPadding = MIN(paddingLeftFromCenter, paddingRightFromCenter);
  29. reactViewFrame.size.width = minPadding*2;
  30. reactViewFrame.origin.x = paddingLeftFromCenter - minPadding;
  31. self.subView.frame = reactViewFrame;
  32. }
  33. }
  34. @end