Reputation: 7304
I have a UIView
with a rectangle size of (414,736). I made a ScrollView
50 in width and 50 in height bigger than UIView
. When I add UIView
to ScrollView
, UIView
stays horizontally is OK, but in vertical it is located at the bottom of the ScrollView
. So that my scrolling part is the top part. But I want UIView
stay on the top part and the bottom part becomes the scrolling area.
How can I locate the UIView
with a specific location onto the ScrollView
?
The following code shows how ScrollView is implemented.
CGRect screenRect = [[UIScreen mainScreen] bounds];
self.scrollView=[[UIScrollView alloc] initWithFrame:screenRect];
self.scrollView.delegate = self;
self.scrollView.clipsToBounds = YES;
[self.scrollView addSubview:self.drawChart];
self.scrollView.contentSize=CGSizeMake(screenRect.size.width+100,screenRect.size.height+50);
self.scrollView.decelerationRate = UIScrollViewDecelerationRateFast;
self.scrollView.backgroundColor = [UIColor colorWithRed:0.564 green:0.439 blue:0.561 alpha:1];
self.view=self.scrollView;
EDIT:
- (void)viewDidLoad {
[super viewDidLoad];
CGRect screenRect = [[UIScreen mainScreen] bounds];
//Database
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
// Build the path to the database file
databasePath = [[NSString alloc]initWithString:[docsDir stringByAppendingPathComponent: @"RECORDS.db"]];
//scroll view
//
self.scrollView=[[UIScrollView alloc] initWithFrame:screenRect];
self.scrollView.delegate = self;
self.scrollView.clipsToBounds = YES;
[self.scrollView addSubview:self.drawChart];
CGRect frame = self.drawChart.frame;
frame.origin = CGPointZero;
self.drawChart.frame = frame;
self.scrollView.contentSize=CGSizeMake(screenRect.size.width+100,screenRect.size.height+50);
self.scrollView.decelerationRate = UIScrollViewDecelerationRateFast;
self.scrollView.backgroundColor = [UIColor colorWithRed:0.564 green:0.439 blue:0.561 alpha:1];
self.view=self.scrollView;
}
Thanks
Upvotes: 1
Views: 1134
Reputation: 14030
after adding the chartview to the scrollview
[self.scrollView addSubview:self.drawChart];
do the following:
CGRect frame = self.drawChart.frame;
frame.origin = CGPointZero;
self.drawChart.frame = frame;
Upvotes: 1