I have a scrollview (IBOutlet); in that scrollview I have added an imageview. I am trying to add a label in the image according to its size. I mean, there are 9 options to put a label in an image: for instance TR (Top Right corner), TC (Top center), C(Center)… Suppose my image is smaller than the iPhone’s resolution, say 300×160. Now, I am loading labels in the image view but it’s not working properly, the alignment of the label is not correct.
Here is my align button code:
-(IBAction)btn_AlignPressed:(UIButton*)sender{
lbl.tag = sender.tag;
[imgView addSubview:lbl];
if (sender.tag == 1) {
lbl.frame = CGRectMake(0, 0, imgView.frame.size.width, imgView.frame.size.height);
} else if(sender.tag == 2) {
lbl.frame = CGRectMake(160-(imgView.frame.size.width/2), 0, imgView.frame.size.width, imgView.frame.size.height);
} else if(sender.tag == 3) {
lbl.frame = CGRectMake(320-imgView.frame.size.width, 0, imgView.frame.size.width, imgView.frame.size.height);
} else if(sender.tag == 4) {
lbl.frame = CGRectMake(0, 210-(imgView.frame.size.height/2), imgView.frame.size.width, imgView.frame.size.height);
} else if(sender.tag == 5) {
lbl.frame = CGRectMake(160-(imgView.frame.size.width/2), 210-(imgView.frame.size.height/2), imgView.frame.size.width, imgView.frame.size.height);
} else if(sender.tag == 6) {
lbl.frame = CGRectMake(320-imgView.frame.size.width, 210-(imgView.frame.size.height/2), imgView.frame.size.width, imgView.frame.size.height);
} else if(sender.tag == 7) {
lbl.frame = CGRectMake(0, 420-imgView.frame.size.height, imgView.frame.size.width, imgView.frame.size.height);
} else if(sender.tag == 8) {
lbl.frame = CGRectMake(160-(imgView.frame.size.width/2), 420-imgView.frame.size.height, imgView.frame.size.width, imgView.frame.size.height);
} else if(sender.tag == 9) {
lbl.frame = CGRectMake(320-imgView.frame.size.width, 420-imgView.frame.size.height, imgView.frame.size.width, imgView.frame.size.height);
}
}
Please help me.
Thanks in advance.
You are only setting x and y values, you will also have to work on the width and height of your label.