. iPhone 6S. , x . , 5S 4S, x . , , 9 18. , . !
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var theImageView: UIImageView!
@IBOutlet weak var theLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
theLabel.frame.size.width = (theImageView.image?.size.width)!
NSNotificationCenter.defaultCenter().addObserver(self, selector: "rotated", name: UIDeviceOrientationDidChangeNotification, object: nil)
}
override func viewDidAppear(animated: Bool) {
if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation))
{
if (theImageView.image?.size.height)! > (theImageView.image?.size.width)! {
theLabel.frame.origin.x = (view.frame.size.width - (theImageView.image?.size.height)!)/2
theLabel.frame.size.width = (theImageView.image?.size.height)!
}
else {
theLabel.frame.origin.x = ((theImageView.image?.size.height)!/2) - 9
theLabel.frame.size.width = rint(view.frame.size.width) - (theImageView.image?.size.height)! + 18
}
}
if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation))
{
theLabel.frame.size.width = theImageView.frame.size.width
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
}
func rotated()
{
if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation))
{
if (theImageView.image?.size.height)! > (theImageView.image?.size.width)! {
theLabel.frame.origin.x = (view.frame.size.width - (theImageView.image?.size.height)!)/2
theLabel.frame.size.width = (theImageView.image?.size.height)!
}
else {
theLabel.frame.origin.x = ((theImageView.image?.size.height)!/2) - 9
theLabel.frame.size.width = rint(view.frame.size.width) - (theImageView.image?.size.height)! + 18
}
}
if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation))
{
theLabel.frame.size.width = theImageView.frame.size.width
}
}