0

我以以下方式将 uiimageview 添加到按钮:

  1. uiimageview 是沿 y 轴的中心(刚刚再次编辑)
  2. uiimageview 的尾随空间总是距离按钮 10 个点

为此,我正在做以下事情

 // Just added these lines 
    UIImage *img                =   [UIImage imageNamed:@"reload.png"];
    indicator                   =   [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, img.size.width, img.size.width)];
    indicator.image             =   img;

    [self.logInButton addConstraints:[NSLayoutConstraint constraintsWithVisualFormat: @"H:|[indicator]-(10)-|"
                                                                                 options:0
                                                                                 metrics:nil
                                                                                   views:NSDictionaryOfVariableBindings(indicator)]];

    [self.logInButton addConstraint:[NSLayoutConstraint constraintWithItem:self.logInButton
                                                              attribute:NSLayoutAttributeCenterY
                                                              relatedBy:NSLayoutRelationEqual
                                                                 toItem:indicator
                                                              attribute:NSLayoutAttributeCenterY
                                                             multiplier:1.0
                                                               constant:0]];

但是,我得到的是 uiimageview 像下面一样伸展

在此处输入图像描述

有没有人对此有任何想法。所有评论都在这里表示赞赏。

4

1 回答 1

0

您的约束是说图像视图应该与左边缘齐平并且距离右侧 10 个点,因此如果按钮大于图像的大小,图像将被拉伸。您要么需要将其在 x 方向居中(并消除右侧的那个),要么为图像视图设置特定大小。

于 2013-02-17T02:17:38.527 回答