gpt4 book ai didi

ios - 分段控件在第一段中显示奇怪的标题

转载 作者:行者123 更新时间:2023-11-28 18:28:13 25 4
gpt4 key购买 nike

我有一个分段控件。它在第一部分显示奇怪的标题。虽然它有时并不总是发生,但我不知道是什么触发了它。自动调整大小模式设置为与内容成比例这里是 iphone、 Storyboard和自动布局约束的快照

Iphone

Storyboard storyboard

自动布局约束 Autolayout constraints

我已经扩展了 SegmentedControl 来满足这里的特定要求是代码

class CustomSegmentedControl: UISegmentedControl {
var current = 0
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
current = self.selectedSegmentIndex
super.touchesBegan(touches, with: event)
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
if current == self.selectedSegmentIndex{
self.sendActions(for: .valueChanged)
}
}
}

View Controller

class MatchingViewController: UIViewController {

@IBOutlet weak var containerView: UIView!
@IBOutlet weak var segmentControl: UISegmentedControl!
@IBOutlet weak var searchHolder: UIView!
@IBOutlet weak var searchTextField: UITextField!
@IBOutlet weak var searchButton: UIButton!

enum tabEnum: Int {
case all = 0
case iceBreaker
case tagged
case connected
}
enum buttonTags: Int{
case searchButton = 101
}
override func viewDidLoad() {
super.viewDidLoad()
setupTags()
setupActions()
setupSegmentControl()
setupSearchBar()


}


func setupTags(){
self.searchButton.tag = buttonTags.searchButton.rawValue
}
func setupActions(){
self.searchButton.addTarget(self, action: #selector(self.didSelect(_:)), for: .touchUpInside)
}
func setupSearchBar() {
self.searchButton.setTitleColor(UIColor.darkGreen(), for: [])
self.searchHolder.layer.borderWidth = 1
self.searchHolder.layer.borderColor = UIColor.darkGreen().cgColor
self.searchHolder.layer.cornerRadius = 5
self.searchTextField.delegate = self
}

func setupSegmentControl() {
segmentControl.addTarget(self, action: #selector(self.didSelectTab(_:)), for: .valueChanged)
didSelectTab(segmentControl)
}



func didSelectTab(_ sender: UISegmentedControl) {
let value = sender.selectedSegmentIndex
self.segmentControl.tintColor = UIColor.darkGreen()

print("selectedIndex \(value)")
let storyBoard = Global.sharedInstance.storyboard
let storyBoardId = value == 0 ? "FirstViewControllerID" : "SecondViewControllerID"
vc = storyBoard.instantiateViewController(withIdentifier: storyBoardId)

if let vc = vc {
vc.setValue(self, forKey: "parentController")
vc.setValue(value, forKey: "tabIndex")
self.containerView.subviews.forEach({ $0.removeFromSuperview() })
self.containerView.addSubview(vc.view)
vc.view.translatesAutoresizingMaskIntoConstraints = false
addChildViewController(vc)
NSLayoutConstraint.activate([
vc.view.leadingAnchor.constraint(equalTo: containerView.leadingAnchor),
vc.view.trailingAnchor.constraint(equalTo: containerView.trailingAnchor),
vc.view.topAnchor.constraint(equalTo: containerView.topAnchor),
vc.view.bottomAnchor.constraint(equalTo: containerView.bottomAnchor)
])
vc.didMove(toParentViewController: self)

}
}


func didSelect(_ sender: UIButton){
if let tag = buttonTags.init(rawValue: sender.tag){
switch tag {
case .searchButton:
self.searchTextField.endEditing(true)
startSearch()
}
}
}
}

最佳答案

在幕后,Xcode 为您的 Storyboard构建 localizable.strings 文件,这些文件使用对象 ID 将 View 对象的字符串映射到条目。您显示的内容看起来像其中一个字符串的字符串名称。如果您编辑 Storyboard的 .strings 文件并更改其中一个字符串映射(例如 "KkS-S7-SCw.segmentTitle"= "All"),那么您可能会得到与您看到的结果完全相同的结果。我的猜测是 Storyboard表面下的可本地化字符串有些困惑。

关于ios - 分段控件在第一段中显示奇怪的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46204067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com