【发布时间】:2014-10-17 10:04:33
【问题描述】:
我想我在 UISegmentedControl 和自动布局方面遗漏了一些东西。
i have a TabbedApplication (UITabBarController), and i created a new UIViewController to act as tab. 在新视图中我添加了 UISegmentedControl,并使用自动布局将其置于顶部。
我想我不完全理解一些东西, 导致 UISegmentedControl 隐藏在 titleBar 下 .你能帮我理解我错过了什么吗? 谢谢。
import Foundation
import UIKit;
class ViewLikes:UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "some title";
var segmentControl:UISegmentedControl = UISegmentedControl(items:["blash", "blah blah"]);
segmentControl.selectedSegmentIndex = 1;
segmentControl.setTranslatesAutoresizingMaskIntoConstraints(false)
self.view.addSubview(segmentControl)
//Set layout
var viewsDict = Dictionary <String, UIView>()
viewsDict["segment"] = segmentControl;
//controls
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-[segment]-|",
options: NSLayoutFormatOptions.AlignAllCenterX,
metrics: nil,
views: viewsDict))
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-[segment]",
options: NSLayoutFormatOptions(0),
metrics: nil,
views: viewsDict))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
【问题讨论】:
-
确保您的导航栏不透明。它应该可以工作。
标签: ios swift uitabbarcontroller uisegmentedcontrol