对于引用:
@interface rjhccViewController : UIViewController{
int myInt;
IBOutlet UIImageView *testcontainer;
IBOutlet UILabel *heightS;
IBOutlet UILabel *widthS;
}
-(IBAction) img1;
-(IBAction) img2;
@end
-(IBAction)img1{
UIImage *img = [UIImage imageNamed:@"p.jpeg"];
[testcontainer setImage:img];
[testcontainer setFrame:CGRectMake(0,0,50,50)];
int myInt = (int) img.size.height;
NSString *imgheight = [NSString stringWithFormat:@"%i",[[NSNumber numberWithFloat:img.size.height] intValue]];
heightS.text = imgheight;
}
所以我把它附在一个按钮上。当我单击该按钮时,图像会显示并报告高度,但容器不会改变大小。当我再次单击该按钮时,它确实会转到正确的CGRectMake...不知道为什么?
抢
如果在将
最后一个 UIImageView 设置为 UIImageView 的图像属性后,需要将 UIImageView 的大小设置为与图像相同,请尝试以下代码:
UIImage *img = [UIImage imageNamed:@"p.jpeg"];
[testcontainer setImage:img];
[testcontainer sizeToFit];