I have a UIScrollView in which I am adding a subview which is a TimeLineView(a UIView).For the purpose of displaying; initially I just did the same and the TimeLineView got displayed without any problem. But now I want to have a UIView just above the UIScrollView where I can display some information about the the timeline.
Do I need to decrease the height of the UIScrollView so that the UIView gets fit on the space above it? If yes, How would I do that?
If there’s another way…then please let me know.
All my initial implementations are as follows :
in .h
@property (nonatomic, readonly) UIScrollView *scrollView;
@property (nonatomic, readonly) TimeLineView *timelineView;
in .m
@synthesize scrollView = scrollView;
@synthesize timelineView = timelineView;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self prepareCustomView];
}
return self;
}
- (id)initWithCoder:(NSCoder *)decoder
{
self = [super initWithCoder:decoder];
if (self) {
[self prepareCustomView];
}
return self;
}
- (void)prepareCustomView {
// Initialization code
// Add main scroll view
[self addSubview:self.scrollView];
// Add timeline view inside scrollview
[self.scrollView addSubview:self.timelineView];
}
- (UIScrollView *)scrollView
{
if (!scrollView) {
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, TOP_BAR_HEIGHT, self.bounds.size.width, self.bounds.size.height-TOP_BAR_HEIGHT-FOOTER_HEIGHT)];
scrollView.contentSize = CGSizeMake(self.bounds.size.width,TIMELINE_HEIGHT);
scrollView.scrollEnabled = TRUE;
scrollView.backgroundColor =[UIColor whiteColor];
scrollView.alwaysBounceVertical = TRUE;
}
return scrollView;
}
Thanks in advance for the help.
Yes you have to change y-axis and decrease the height of scrollview by the height of your UIView.You have to change the frame of your scrollview as follows if the scrollview is just below UIView:
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, UIViewFrame.size.height+UIViewFrame.origin.y, self.bounds.size.width, self.bounds.size.height-TOP_BAR_HEIGHT-FOOTER_HEIGHT-UIViewFrame.size.height)];
where UIViewFrame is the frame of your UIView.