forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRCCCustomTitleView.m
55 lines (41 loc) · 1.46 KB
/
RCCCustomTitleView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// RCCTitleView.m
// ReactNativeNavigation
//
// Created by Ran Greenberg on 26/04/2017.
// Copyright © 2017 artal. All rights reserved.
//
#import "RCCCustomTitleView.h"
@interface RCCCustomTitleView ()
@property (nonatomic, strong) UIView *subView;
@property (nonatomic, strong) NSString *subViewAlign;
@end
@implementation RCCCustomTitleView
-(instancetype)initWithFrame:(CGRect)frame subView:(UIView*)subView alignment:(NSString*)alignment {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
self.subView = subView;
self.subViewAlign = alignment;
subView.frame = self.bounds;
[self addSubview:subView];
}
return self;
}
-(void)layoutSubviews {
[super layoutSubviews];
if ([self.subViewAlign isEqualToString:@"fill"]) {
self.subView.frame = self.bounds;
}
else {
CGFloat superViewWidth = self.superview.frame.size.width;
CGFloat paddingLeftFromCenter = (superViewWidth/2) - self.frame.origin.x;
CGFloat paddingRightFromCenter = self.frame.size.width - paddingLeftFromCenter;;
CGRect reactViewFrame = self.subView.bounds;
CGFloat minPadding = MIN(paddingLeftFromCenter, paddingRightFromCenter);
reactViewFrame.size.width = minPadding*2;
reactViewFrame.origin.x = paddingLeftFromCenter - minPadding;
self.subView.frame = reactViewFrame;
}
}
@end