图像在景观中拉伸如何修复?

时间:2016-02-22 11:04:04

标签: ios swift uiimageview

嗨我以swift方式开发了视图控制器,它在纵向模式下完美工作,而在横向模式下图像是拉伸而不是调整,我使用图像XCassests来修复尺寸问题。

让blahIMAGE = UIImage(命名:" blah")

    myFirstButton.setBackgroundImage(blahIMAGE, forState: .Normal)

    myFirstButton.frame = CGRectMake(50, 100, 100, 100)

    myFirstButton.addTarget(self, action: "pressed:", forControlEvents: .TouchUpInside)
    self.view.addSubview(myFirstButton)

1 个答案:

答案 0 :(得分:1)

这里发生的事情是,当您从纵向更改为横向时,UIContentMode不会发生变化。您需要做的是让控制器在设备转向任一侧时重绘所有元素。

self.view.contentMode = UIViewContentMode.Redraw

或者,如果您只想修复图像,请使用:

yourImageView.contentMode = UIViewContentMode.Redraw
相关问题