改变图像的界限取决于图像的大小

时间:2013-10-04 04:41:12

标签: iphone ios uiimageview size bounds

我试图让UIImage对象的界限改变取决于图像大小。我不知道为什么图像边界不会更新

@interface AsunaEventViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *AsunaImageView;
@end

@implementation AsunaEventViewController
CGFloat x = self.AsunaImageView.bounds.center.x; 
CGFloat y = self.AsunaImageView.bounds.center.y;
if (self.answer == 0){ 
    CGSize imageSize = [[UIImage imageNamed:@"qwr.png"] size]; 
    CGRect imageBounds = CGRectMake(x - imageSize.width/2, y - imageSize.height/2, imageSize.width, imageSize.height);
    self.AsunaImageView.frame = imageBounds; 
    self.AsunaImageView.image = [UIImage imageNamed:@"rts.png"]

1 个答案:

答案 0 :(得分:2)

更改UIImageview的图像名称

if (self.answer == 0){ 
   CGSize imageSize = [[UIImage imageNamed:@"qwr.png"] size]; 
   CGRect imageBounds = CGRectMake(x - imageSize.width/2, y - imageSize.height/2, imageSize.width, imageSize.height);
   self.AsunaImageView.frame = imageBounds; 
   self.AsunaImageView.image = [UIImage imageNamed:@"qwr.png"];
}