GTP_Tech
GTP_Tech

Reputation: 155

ios Set UIScrollView's origin position

By default as we all know, a view's origin is at the top-left corner of the iPhone screen. I'm trying to do something very simple with no luck, to change it! I would like to set my UIScrollView's origin to the bottom-left corner (programmatically ofc). I was hoping to avoid transformations (if needed)...is there a simple way to do so?

Appreciate your help :)

Upvotes: 1

Views: 2992

Answers (5)

Jakub Truhlář
Jakub Truhlář

Reputation: 20710

self.scrollView property contentOffset

Upvotes: 0

Rajesh Loganathan
Rajesh Loganathan

Reputation: 11217

Try this:

You can change one any one position by leaving others as default

1.Before modified

UIScrollView *mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,320,500)];

2.If need to modify any one

UIScrollView *mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(10,self.view.frame.origin.y,self.view.frame.size.width,self.view.frame.size.height)];

// or

UIScrollView *mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x,10,self.view.frame.size.width,self.view.frame.size.height)];

//or

UIScrollView *mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y,320,self.view.frame.size.height)];

//or

UIScrollView *mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y,self.view.frame.size.width,500)];

Upvotes: 0

alper_k
alper_k

Reputation: 512

I assume that you want to make a Scroll View that fits to the left bottom corner of your view.

You can do that. Let's say your scroll view's size is 100x100.

UIScrollView* sc = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 360, 100, 100)];
    [self.view addSubview:sc];

That Scroll View's left bottom corner has the same point with your View.

Upvotes: 0

Vishal Singh
Vishal Singh

Reputation: 4480

[self.scrollView setFrame:CGRectMake(0,self.view.frame.size.height,self.view.frame.size.width, -self.view.frame.size.height];

i am not sure what your looking for but the above line will set the origin of scrollview at bottom left, but scrollview will still be visible on the whole view if thats what your looking for.

Upvotes: 1

simeon
simeon

Reputation: 4626

This category will give you a convenience property that can be used to manipulate a UIView by its lower left origin:

@interface UIView (LowerLeftOrigin)

@property (nonatomic, assign) CGPoint lowerLeftOrigin;

@end


@implementation UIView (LowerLeftOrigin)

- (void) setLowerLeftOrigin:(CGPoint)lowerLeftOrigin
{
    self.frame = CGRectMake(lowerLeftOrigin.x, 
                            lowerLeftOrigin.y - self.bounds.size.height, 
                            self.bounds.size.width, self.bounds.size.height);
}

- (CGPoint) lowerLeftOrigin
{
    return CGPointMake(self.frame.origin.x,
                       self.frame.origin.y + self.bounds.size.height);
}

@end

Upvotes: 0

Related Questions