[英] How do I use a UISegmentedControl to switch views?
我正在试图弄清楚如何使用UISegmentedControl的不同状态来切换视图,就像苹果在App Store中在"顶级付费"和"顶级免费"之间快速切换时一样.
我正在试图弄清楚如何使用UISegmentedControl的不同状态来切换视图,就像苹果在App Store中在"顶级付费"和"顶级免费"之间快速切换时一样.
The simplest approach is to have two views that you can toggle their visibility to indicate which view has been selected. Here is some sample code on how it can be done, definitely not an optimized way to handle the views but just to demonstrate how you can use the UISegmentControl to toggle the visible view:
- (IBAction)segmentSwitch:(id)sender {
UISegmentedControl *segmentedControl = (UISegmentedControl *) sender;
NSInteger selectedSegment = segmentedControl.selectedSegmentIndex;
if (selectedSegment == 0) {
//toggle the correct view to be visible
[firstView setHidden:NO];
[secondView setHidden:YES];
}
else{
//toggle the correct view to be visible
[firstView setHidden:YES];
[secondView setHidden:NO];
}
}
You can of course further re-factor the code to hide/show the right view.
将 SwiftUI 与 @AppStorage 和动态函数调用一起使用
使用 RxDatasources 作为数据源时如何填充自定义页眉/页脚视图
为 iOS 模拟器构建 Xcode,但在为 iOS 构建的对象文件中链接,用于架构“arm64”
Xcode 11 向后兼容性:“UIWindowScene 仅在 iOS 13 或更高版本中可用”
警告:子上下文类型失败:提供给“CellRenderer”的“数字”类型的子上下文“virtualizedCell.cellKey”无效,应为“字符串”
UIView 中的 safeAreaInsets 在 iPhone X 上为 0
Xcode 8.3.3“没有具有 iTunes Connect 访问权限的帐户”