2015-04-04 35 views
1

我很难尝试获得UIImageView的正确对齐方式。UIImageView中的奇怪对齐行为

现在,我有一个非常简单的故事板,只有一个UIButton和UIImageView在一个视图中(见附图)。

的出口被设置在所述控制器:

@property (weak, nonatomic) IBOutlet UIImageView *imageViewer; 

对于UIImageView,视图模式设定为Aspect FitUIImageView的边缘与ViewController的边缘对齐。当点击UIButton,它会触发与图像更新UIImageView

@synthesize imageViewer; 
- (IBAction)submitPressed:(id)sender { 

    ... //url declared in this hidden chunk 

    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]]; 
    imageViewer.image = [UIImage imageWithData:imageData]; 
} 

enter image description here

正如你所看到的,由于某种原因在左侧保证金和虽然UIImageView已定到Aspect Fit,裁剪发生在图像的右边缘(红色部分已被裁剪掉)。

我试着把正常的边缘放在四周,而且图像在右边更加剪裁。我认为这可能是NSData的问题,并试图直接在UIWebView中加载远程映像,问题依然存在。

有谁知道为什么会发生这种情况?先谢谢你。

+1

你在使用autolayout吗? – 2015-04-04 04:58:33

+0

我不这么认为。 – 2015-04-04 05:02:28

+0

原来我是 – 2015-04-04 05:15:36

回答

0

应用限制到您的UIImageView

NIB选择的UIImageView,然后点击编辑>针>前导空格,以上海华。然后在属性检查器集合常量到。做同样的事情并将Trainling Space应用于SuperView