UISearchBar范围栏位置?

时间:2014-10-10 08:44:47

标签: ios swift uisearchbar

我在iPad应用程序上,我想知道是否可以将Scope Bar从右边移动到我的UISearchBar到另一个位置?

enter image description here

我想将我的Scope Bar放在我的搜索栏下。这可能吗?

提前致谢。

1 个答案:

答案 0 :(得分:2)

好的,这是我的解决方案。我实现了自己的分段控制,为搜索范围创造了可能性。

    let categories = ["Scope1", "Scope2", "Scope3"]
    segmentedControl.addTarget(self, action: "changeScope:", forControlEvents: .ValueChanged) 
    segmentedControl.frame = CGRectMake(8, 5, 800, 30)
    segmentedControl.backgroundColor = UIColor.whiteColor()
    segmentedControl.tintColor = UIColor.darkGrayColor()

    // add it in a scrollView, because ill got too much categories here. Just if you need that:

    scrollView.contentSize = CGSizeMake(segmentedControl.frame.size.width + 16, segmentedControl.frame.size.height-1)
    scrollView.showsHorizontalScrollIndicator = false;
    // set first category
    segmentedControl.selectedSegmentIndex = 0
    scrollView.addSubview(segmentedControl)

以下是范围栏的功能,当用户切换范围时,您需要执行的操作:

func changeScope(sender: UISegmentedControl) {
    switch(sender.selectedSegmentIndex) { 
    }
 }

在我的情况下,ill从Webservice获得了几个resultArrays,而ill只显示了所选的结果(通常不好将它们添加到1个巨大的resultSet中)

希望有可能帮助其他人。

相关问题