UISegmentedControl(分页控制器) AND UISlider(滑块控制器)

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UIImageView * animatedImageView = [[UIImageView alloc]initWithFrame:CGRectMake(60, 80, 200, 300)];
    animatedImageView.backgroundColor = [UIColor redColor];
    animatedImageView.tag = 100;
    [self.view addSubview:animatedImageView];
    [animatedImageView release];
    
    NSMutableArray * arrayImages = [NSMutableArray array];
    for (int i = 1; i < 8; i++) {
        
        [arrayImages addObject:[UIImage imageNamed:[NSString stringWithFormat:@"huoju_%i.tiff",i]]];

    }
    // 添加要实现动画效果的一系列图片
    animatedImageView.animationImages = arrayImages;

#pragma mark - 分段控制器
    //initWithItems:可以添加图片或者字符串
    UISegmentedControl * segment = [[UISegmentedControl alloc]initWithItems:@[@"statr",@"stop",@"HMT"]];
    segment.frame = CGRectMake(10, 20, 300, 40);
    // 分了几段
    NSLog(@"%lu",segment.numberOfSegments);
    // 选中时,是一直呈现高亮状态(NO)还是瞬间的高亮(YES)
    segment.momentary = YES;
    [segment addTarget:self action:@selector(onClickSegmentedControl:) forControlEvents:UIControlEventValueChanged];
    // 把下标为2的区段,设置为不可点击
    [self.view addSubview:segment];
    [segment release];
    
    
    // 滑动控制器
    UISlider * slider  = [[UISlider alloc]initWithFrame:CGRectMake(10, 500, 300, 40)];
    slider.maximumValue = 3;
    slider.minimumValue = 0.1;
    NSLog(@"%f",slider.value);
    [self.view addSubview:slider];
    [slider release];
    [slider addTarget:self action:@selector(changeSliderValue:) forControlEvents:UIControlEventValueChanged];
  
}


- (void)onClickSegmentedControl:(UISegmentedControl *)segmented{
    
     // selectedSegmentIndex
    if (segmented.selectedSegmentIndex == 0) {
        // 启动动画
        [((UIImageView *)[self.view viewWithTag:100]) startAnimating];
        
    } else {
        // 停止动画
        [((UIImageView *)[self.view viewWithTag:100]) stopAnimating];
        
    }
}

- (void)changeSliderValue:(UISlider *)sLider{
    
    // 通过滑动控件,增减速度
    ((UIImageView *)[self.view viewWithTag:100]).animationDuration = sLider.value;
    [((UIImageView *)[self.view viewWithTag:100]) startAnimating];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

旅游网站导航栏控制器的关键代码会根据具体实现方式不同而有所不同,下面是一个简单的示例: ```swift class NavigationBarViewController: UIViewController { // 导航栏控件 let searchBar = UISearchBar() let segmentedControl = UISegmentedControl(items: ["国内游", "出境游", "周边游"]) let filterButton = UIButton(type: .system) override func viewDidLoad() { super.viewDidLoad() // 添加导航栏控件 searchBar.placeholder = "搜索旅游目的地" navigationItem.titleView = searchBar segmentedControl.selectedSegmentIndex = 0 navigationItem.titleView = segmentedControl filterButton.setTitle("筛选", for: .normal) navigationItem.rightBarButtonItem = UIBarButtonItem(customView: filterButton) // 设置导航栏外观 navigationController?.navigationBar.tintColor = .white navigationController?.navigationBar.barTintColor = .blue navigationController?.navigationBar.isTranslucent = false navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] } // 搜索按钮点击事件 func searchBarSearchButtonClicked(_ searchBar: UISearchBar) { // 处理搜索逻辑 } // 分段控件点击事件 @objc func segmentedControlValueChanged(_ segmentedControl: UISegmentedControl) { // 处理分段逻辑 } // 筛选按钮点击事件 @objc func filterButtonTapped(_ sender: UIButton) { // 处理筛选逻辑 } } ``` 这个示例中,`NavigationBarViewController` 是一个 UIViewController 子类,用于管理导航栏控件。在 `viewDidLoad()` 方法中,我们添加了三个控件:`searchBar`、`segmentedControl` 和 `filterButton`。然后,我们还对导航栏外观进行了一些设置。最后,我们还添加了三个事件处理方法:`searchBarSearchButtonClicked(_:)`、`segmentedControlValueChanged(_:)` 和 `filterButtonTapped(_:)`。这些方法会根据不同的控件事件来处理对应的业务逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值