Reputation: 335
Hey guys when you set the coordinates of a UIImageView it sets the UIImageView respective to the top right corner. Is there any way to make the coordinates apply to the bottom left?
Upvotes: 0
Views: 167
Reputation: 39978
Answer for second question... Just import these files where you are creating uiimageview
@interface UIImageView (MyCategory)
- (id)init;
@end
@implementation UIImageView (MyCategory)
- (id)init {
self = [super init];
if (self) {
self.layer.anchorPoint = CGPointMake(0, 1);
}
return self;
}
@end
The above code may cause come problem as the init of UIImageView might be doing some other task too, so you should do like
@interface UIImageView (MyCategory)
- (id)initMyImageView;
@end
@implementation UIImageView (MyCategory)
- (id)initMyImageView {
[self init];
self.layer.anchorPoint = CGPointMake(0, 1);
return self;
}
@end
and use it like [[UIImageView alloc] initMyImageView];
Upvotes: 0
Reputation: 39978
if you have the reference of the view then you can set its anchor point uisng
view.layer.anchorPoint = CGPointMake(0,1);
//your lower left corner..
0,0 means upper left corner
default is 0.5,0.5 which is center
max is 1,1 which is lower right corner
and don't forget to import <QuartzCore/QuartzCore.h>
Upvotes: 1
Reputation: 2230
UIImageView
positioning settings inherited from UIView
. That is why you can only manipulte by frame
and center
properties of your UIImageView
. But you can 'simulate' left-bottom corner positioning:
UIView *yourView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
int bottomLeftX, bottomLeftY;
CGRect rect = yourView.frame;
yourView.frame = CGRectMake(bottomLeftX, bottomLeftY - rect.size.height, rect.size.width, rect.size.height);
Upvotes: 0