UISegmentedControl
의 값을 프로그래밍 방식으로 신속하게 입력 할 수 있습니까?swift를 사용하여 프로그래밍 방식으로 UISegmentedControl 채우기
1
A
답변
4
let segmentedControl = UISegmentedControl()
segmentedControl.insertSegment(withTitle: "Title", at: 0, animated: true)
segmentedControl.setTitle("Another Title", forSegmentAt: 0)
1
나는 @ RyuX51 의 솔루션을 사용하여, 내 문제를 해결하고 내 코드는 지금 :
class MyCustomViewController: UIViewController{
@IBOutlet weak var ServicesSC: UISegmentedControl!
override func viewDidLoad() {
super.viewDidLoad()
ServicesSC.removeAllSegments()
ServicesSC.insertSegment(withTitle: "Title", at: 0, animated: true)
ServicesSC.setTitle("Another Title", forSegmentAt: 0)
}
}
2
내가 착각하고 있지 않다 경우, 당신은 당신이 세그먼트에 "UISegmentedControl"을 추가 할 것을 의미 인터페이스 빌더를 사용하지 않고 프로그래밍 방식으로
는네, 가능합니다 :
// Assuming that it is an "IBOutlet", you can do this in your "ViewController":
class ViewController: UIViewController {
@IBOutlet weak var segmentedControl: UISegmentedControl!
override func viewDidLoad() {
super.viewDidLoad()
// remove all current segments to make sure it is empty:
segmentedControl.removeAllSegments()
// adding your segments, using the "for" loop is just for demonstration:
for index in 0...3 {
segmentedControl.insertSegmentWithTitle("Segment \(index + 1)", atIndex: index, animated: false)
}
// you can also remove a segment like this:
// this removes the second segment "Segment 2"
segmentedControl.removeSegmentAtIndex(1, animated: false)
}
// and this is how you can access the changing of its value (make sure that event is "Value Changed")
@IBAction func segmentControlValueChanged(sender: UISegmentedControl) {
print("index of selected segment is: \(sender.selectedSegmentIndex)")
}
}
관련 문제
- 1. UISegmentedControl 프로그래밍 방식으로 다시 설정
- 2. UIBarButtonItems가 Swift를 사용하여 프로그래밍 방식으로 생성되었습니다.
- 3. 프로그래밍 방식으로 listview 채우기
- 4. 프로그래밍 방식으로 데이터베이스 채우기
- 5. Swift를 프로그래밍 방식으로 붙여 넣기하려면 어떻게해야합니까?
- 6. swift를 사용하여 프로그래밍 방식으로 IMEI 번호를 얻는 방법
- 7. DataGridView ComboBoxCell 프로그래밍 방식으로 채우기
- 8. 배열을 프로그래밍 방식으로 애니메이션으로 채우기
- 9. 설정 UISegmentedControl 텍스트 프로그래밍 변수
- 10. DX11 프로그래밍 방식으로 3D 텍스처 채우기
- 11. 프로그래밍 방식으로 ASP.net 데이터 테이블 채우기
- 12. Swift를 통해 프로그래밍 방식으로 내 앱의 로케일을 변경하려면 어떻게해야합니까?
- 13. 프로그래밍 방식으로 공유 지점에 선택 필드 채우기
- 14. IF 수식으로 프로그래밍 방식으로 Excel 셀 채우기
- 15. TcxGrid의 cxCheckCombox 속성을 프로그래밍 방식으로 채우기
- 16. android : layout_weight가있는 TableLayout에 프로그래밍 방식으로 채우기
- 17. 프로그래밍 방식으로 모든 노래로 목록 채우기?
- 18. CheckboxList에 프로그래밍 방식으로 선택 옵션을 채우기
- 19. GridView에 스크롤 막대 추가 프로그래밍 방식으로 채우기
- 20. WebBrowser WPF 컨트롤을 사용하여 프로그래밍 방식으로 웹 양식 채우기
- 21. UISegmentedControl 선택한 세그먼트가 변경되었습니다.
- 22. swift를 사용하여 메인 창 시작하기
- 23. Swift에서 프로그래밍 방식으로 NSWindow 만들기
- 24. Powershell을 사용하여 프로그래밍 방식으로 계약 개체 속성을 프로그래밍 방식으로 설정하십시오.
- 25. axlsx를 사용하여 프로그래밍 방식으로 셀을 프로그래밍 방식으로 참조하는 방법
- 26. 프로그래밍 방식으로 Swift에서 SKTileMapNode 만들기
- 27. Swift를 사용하여 버튼에 제약 조건 추가 프로그래밍 방식으로 제약 조건 추가
- 28. XCode에서 Swift를 사용하여 새 NSWindow를 만들고 프로그래밍 방식으로 내용을 추가하는 방법은 무엇입니까?
- 29. UISegmentedControl을 프로그래밍 방식으로 어떻게 표시합니까?
- 30. UISegmentedControl 텍스트 변경