自定义顶部标签栏,只有文本swift

时间:2018-04-16 06:26:14

标签: ios swift xcode

我想在页面顶部创建一个标签栏,只包含文字,点击一下就会更改文字颜色并为所选项目加下划线......如下图所示...

enter image description here

我搜索了很多,但没有找到帮助我实现这一目标的东西..

有人可以告诉我该怎么做?

1 个答案:

答案 0 :(得分:0)

取三个按钮和三个imageviews.take三个按钮的动作,并为图像和标签取出口,如下所示。使用此链接轻松识别。它非常适合您。 click here

class ViewController: UIViewController
{

@IBOutlet weak var imgDetails: UIImageView!
@IBOutlet weak var imgPassword: UIImageView!
@IBOutlet weak var imglocations: UIImageView!


@IBOutlet weak var lblDetailsTittle: UILabel!
@IBOutlet weak var lblPasswordTittle: UILabel!
@IBOutlet weak var lblLocationTittle: UILabel!



override func viewDidLoad() 
{
    super.viewDidLoad()


  //if you want select by default Details use this code otherwise uncomment it.

imgDetails.backgroundColor = UIColor.green
imgPassword.backgroundColor = UIColor.clear
imglocations.backgroundColor = UIColor.clear

lblDetailsTittle.textColor = UIColor.black
lblPasswordTittle.textColor = UIColor.lightGray
lblLocationTittle.textColor = UIColor.lightGray

}


@IBAction func btnDetailsTouchUpInSide(_ sender: Any)
{
    imgDetails.backgroundColor = UIColor.green
    imgPassword.backgroundColor = UIColor.clear
    imglocations.backgroundColor = UIColor.clear

    lblDetailsTittle.textColor = UIColor.black
    lblPasswordTittle.textColor = UIColor.lightGray
    lblLocationTittle.textColor = UIColor.lightGray
}
@IBAction func btnPasswordTouchUpInSide(_ sender: Any)
{
    imgPassword.backgroundColor = UIColor.green
    imgDetails.backgroundColor = UIColor.clear
    imglocations.backgroundColor = UIColor.clear

    lblPasswordTittle.textColor = UIColor.black
    lblLocationTittle.textColor = UIColor.lightGray
    lblDetailsTittle.textColor = UIColor.lightGray
}

@IBAction func btnLocationsTouchUpInSide(_ sender: Any)
{
    imglocations.backgroundColor = UIColor.green
    imgDetails.backgroundColor = UIColor.clear
    imgPassword.backgroundColor = UIColor.clear

    lblLocationTittle.textColor = UIColor.black
    lblPasswordTittle.textColor = UIColor.lightGray
    lblDetailsTittle.textColor = UIColor.lightGray
}


}