我有一个scrollview(IBOutlet);在该scrollview中,我添加了一个imageview。我试图根据图像大小在图像中添加标签。我的意思是,有9个选项可以在图像中放置标签:例如TR(右上角),TC(顶部中心),C(中心)...假设我的图像小于iPhone的分辨率,比如300x160。现在,我在图像视图中加载标签,但它无法正常工作,标签的对齐方式不正确。 这是我的对齐按钮代码:
-(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);
}
}
请帮帮我。
提前致谢。
答案 0 :(得分:0)
您只需设置x和y值,您还必须处理标签的宽度和高度。