【问题标题】:Setting constraints in empty ViewController xcode 5在空的 ViewController xcode 5 中设置约束
【发布时间】:2014-02-10 09:48:43
【问题描述】:

我有一个空的ViewController。我正在以编程方式设置背景图像。

- (void)setBackGroundImg:(NSString*) name {

    UIGraphicsBeginImageContext(self.view.frame.size);
    [[UIImage imageNamed:name] drawInRect:self.view.bounds];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    self.view.backgroundColor = [UIColor colorWithPatternImage:image];

}

问题: 我正在模拟器中运行应用程序。如果没有旋转,它看起来像这样。

但是当我旋转模拟器时,应用看起来像这样

知道如何解决此问题。我正在使用自动布局开启处理Xcode 5。我看不出如何在空的ViewController中设置约束@

【问题讨论】:

  • 图案图像会自我复制。你想达到什么目的?也许可以通过其他方式完成。
  • @vokilam 我想先摆脱这种重复
  • 当我旋转模拟器图像时这可能吗?
  • 自转是什么意思?
  • @vokilam 你可以在图片中看到,模拟器旋转时图像不旋转

标签: ios objective-c xcode5 autolayout nslayoutconstraint


【解决方案1】:

如果您希望图像在设备旋转时自动旋转,请将图像显示在 UIImageView 内,而不是手动绘制图像。查看UIImageView 的文档。

【讨论】:

    【解决方案2】:

    只需使用 9-path,例如:

    self.view.backgroundColor = [UIColor colorWithPatternImage:[image resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)]];
    

    【讨论】:

      猜你喜欢
      • 2019-03-28
      • 1970-01-01
      • 1970-01-01
      • 2020-07-12
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      • 2012-12-08
      • 1970-01-01
      相关资源
      最近更新 更多