定心两个侧由端的对象 [英] Centering two side-by-side objects
问题描述
我试图遵循此处描述的解决方案:
I'm trying to follow the solution described here:
<一个href=\"http://stackoverflow.com/questions/33544940/x$c$c-7-autolayout-constraints-how-to-make-2-images-stay-horizontally-in-the-ce/33545857#33545857\">X$c$c 7自动布局约束:如何让2图像中心水平保持
但它不是为我工作。
以上是从属性检查器的截图,我结束了约束:
These are the screenshots from the Attribute Inspector for the constraints that I ended up with:
任何人都可以看到我错了?
Can anyone see where I am going wrong?
谢谢!
推荐答案
我现在意识到什么问题是。我已经把在故事板所有正确的约束,但是我还没有添加必要的code到视图控制器。我只是使用由X code当你创建一个项目(我没有甚至创造IB网点两个选择器视图)。
I realise now what the issue was. I had put in all the correct constraints on the Storyboard but I had not added the necessary code to the View Controller. I was simply using the View Controller that is automatically generated by Xcode when you create a project (I had not even created IB outlets for the two picker views).
现在,当我添加此code到VC,两个并排侧采摘的布局显示细腻:
Now, when I add this code into the VC, the layout with the two side-by-side pickers displays fine:
import UIKit
类的ViewController:UIViewController的,UIPickerViewDataSource,UIPickerViewDelegate {
class 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.
}
}
感谢您的答复!
这篇关于定心两个侧由端的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!