UISegmentedControl隐藏UITableView的一部分

时间:2018-05-24 23:04:53

标签: swift uitableview uisegmentedcontrol

我试图在UITableView上面实现UISegmentedControl。但UISegmentedControl出现在UITableView的顶部,因此它隐藏了第一个单元格的某些部分。我应该为UITableView添加保证金吗?那么如何添加与UISegmentedControl programmaticaly相同高度的边距?

class ViewController: UIViewController {

  @IBOutlet weak var colorTableView: UITableView!

override func loadView() {
    super.loadView()

    //UIsegmented contral test
    let items = ["All", "Blue", "Green", "Red", "Yellow"]
    let customSC = UISegmentedControl(items: items)
    customSC.selectedSegmentIndex = 0

    let frame = UIScreen.main.bounds
    customSC.frame = CGRect(x:frame.minX, y:frame.minY+50, width: frame.width, height: frame.height*0.08)

    // Style the Segmented Control
    customSC.layer.cornerRadius = 5.0 
    customSC.backgroundColor = UIColor.black
    customSC.tintColor = UIColor.white

    // Add target action method
   //customSC.addTarget(self, action: Selector("changeColor:"), for: .valueChanged)


    self.view.addSubview(customSC)

}

0 个答案:

没有答案