我试图按照此处描述的解决方案:
XCode 7 Autolayout Constraints: How to make 2 images stay horizontally in the center
但它不适合我。
这些是来自Attribute Inspector的屏幕截图,其中列出了我最终得到的约束:
谁能看到我哪里出错了?
谢谢!
答案 0 :(得分:0)
你改变了约束 - 图像视图的前导/尾随必须连接到超视图的中心,以实现你想要做的事情。
答案 1 :(得分:0)
答案 2 :(得分:0)
答案 3 :(得分:0)
我现在意识到问题是什么。我在Storyboard上输入了所有正确的约束,但我没有将必要的代码添加到View Controller中。我只是在创建项目时使用由Xcode自动生成的View Controller(我甚至没有为两个选择器视图创建IB出口)。
现在,当我将此代码添加到VC中时,带有两个并排选择器的布局显示正常:
import UIKit
类ViewController:UIViewController,UIPickerViewDataSource,UIPickerViewDelegate {
var pickerDataSource = ["inch", "feet","mile","meter","yard","kilometer"];
@IBOutlet weak var picker1: UIPickerView!
@IBOutlet weak var picker2: UIPickerView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
picker1.dataSource = self;
picker1.delegate = self;
picker2.dataSource = self;
picker2.delegate = self;
}
func CreateColor(hexAlpha: Int, hexRed: Int, hexGreen: Int, hexBlue: Int) -> CGColor{
return UIColor(red: CGFloat(hexRed)/255.0, green: CGFloat(hexGreen)/255.0, blue: CGFloat(hexBlue)/255.0, alpha: CGFloat(hexAlpha)/255.0).CGColor
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerDataSource.count;
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return pickerDataSource[row]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
感谢您的所有回复!