嗨,我想创建一个包含 20 多个项目的动态 UISegmented 视图。我试过了,但输出是这样的。
文本被切片不完全可见。我希望它左右滚动并显示全文。有人可以帮我解决这个问题。tnx
视图控制器
override func viewDidLoad() {
super.viewDidLoad()
let items = ["All Fruits", "Orange", "Grapes", "Banana", "Mango", "papaya", "coconut", "django"]
let filtersSegment = UISegmentedControl(items: items)
filtersSegment.frame = CGRect.init(x: 10, y: 60, width: 300, height: 50)
filtersSegment.selectedSegmentIndex = 0
filtersSegment.tintColor = UIColor.black
filtersSegment.addTarget(self, action: #selector(self.filterApply), for: UIControlEvents.valueChanged)
self.view.addSubview(filtersSegment)
}
@objc private func filterApply(segment:UISegmentedControl) -> Void {
print("Selected Index : \(segment.selectedSegmentIndex)")
}