设置分段导航器

一、设置分段导航器

在ViewController。m里写

- (void)viewDidLoad {

[super viewDidLoad];

[self creatView];

}

// 设置页面

- (void)creatView{

UISegmentedControl *seg = [[UISegmentedControl alloc] initWithFrame:CGRectMake(5, 50, fDeviceWidth-10, 29)];

[seg insertSegmentWithImage:@"按钮button" atIndex:0 animated:YES];

[seg insertSegmentWithImage:@"标签label" atIndex:1 animated:YES];

seg.tintColor = [UIColor redColor];

seg.selectedSegmentIndex = 0;

[seg addTarget:self action:@selector(seg:) forControlEvents:UIControlEventValueChanged];

[self.view addSubview:seg];

// 初始化button 和 label 页面的位置

_button = [[ButtonView alloc] initWithFrame:CGRectMake(0, 160, fDeviceWidth, fDeviceHeight)];

[self.view addSubview:_button];

_label = [[LabelView alloc] initWithFrame:CGRectMake(fDeviceWidth, 160, fDeviceWidth, fDeviceHeight)];

[self.view addSubview:_label];

}

// 页面之间的切换

- (void)seg:(UISegmentedControl *)Seg{

if (Seg.selectedSegmentIndex == 0) {

Seg.selectedSegmentIndex = 0;

[UIView animateWithDuration:0.2 animations:^{

_button.hidden = NO;

_button.frame = CGRectMake(0, 80, fDeviceWidth, fDeviceHeight - 30) ;

_label.frame = CGRectMake(fDeviceWidth, 50, fDeviceWidth, fDeviceHeight);

}];

}else{

Seg.selectedSegmentIndex = 1;

[UIView animateWithDuration:0.2 animations:^{

_button.frame = CGRectMake(-fDeviceWidth, 50, fDeviceWidth, fDeviceHeight);

_label.frame = CGRectMake(0, 80, fDeviceWidth, fDeviceHeight - 30) ;

_button.hidden = YES;

}];

}

}

二、设置导航的2个页面 button页面 和 label 页面

①、

_oneButton = [[UIButton alloc] initWithFrame:CGRectMake( 20, 20, 20, 20)];

_oneButton.backgroundColor = [UIColor brownColor];

[self addSubview:_oneButton];

_twoButton = [[UIButton alloc] initWithFrame:CGRectMake(50, 50, 50, 50)];

_twoButton.backgroundColor = [UIColor greenColor];

[self addSubview:_twoButton];

②、

_oneLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 90, 200, 30)];

_oneLabel.text = @"只要功夫深";

_oneLabel.font = [UIFont systemFontOfSize:13];

[self addSubview:_oneLabel];

_twoLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 200, 200, 30)];

_twoLabel.text = @"调查2222";

_twoLabel.font = [UIFont systemFontOfSize:15];

[self addSubview:_twoLabel];

时间: 2025-02-01 15:01:45

设置分段导航器的相关文章

077设置分段卡某个选项不可用

效果如下: ViewController.h 1 #import <UIKit/UIKit.h> 2 3 @interface ViewController : UIViewController 4 @end ViewController.m 1 #import "ViewController.h" 2 3 @interface ViewController () 4 - (void)layoutUI; 5 @end 6 7 @implementation ViewCont

IOS的segmentedControl(分段器控件)的一些常用属性

#pragma mark - 创建不同的分段器 //初始化方法:传入的数组可以是字符串也可以是UIImage对象的图片数组 UISegmentedControl *mysegmented = [[UISegmentedControl alloc] initWithItems:@[@"左边",@"我是中间",@"右边"]]; mysegmented.frame = CGRectMake(50, 200, kScreenWidth-100, 40);

iOS中的分段控件(UISegmentedControl)和滑块控件(UISlider)

#import "RootViewController.h" @interface RootViewController () @end @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //分段控件 //1.创建控件 /* NSArray *items = @[@"轻拍

分段控件 (UISegmentedControl)

一. 分段控件 (UISegmentedControl) 控件展示 : 1. UISegmentedControl 控件属性 (1) Style 属性 Style 属性 :       -- Plain : 分段控件使用最普通的风格; -- Bordered : 在最普通风格上添加一圈边框; -- Bar : 分段控件使用工具条风格; (2) State 属性 State 属性 : -- Momentary 复选框 : 勾选复选框后, 分段控件不保存控件状态, 如果勾选后, 点击时高亮, 点击后

iOS开发之分段控制器(UISegmentedControl)

今天我们来说下iOS中的分段选择控制器UISegmentedControl,这一控件有什么作用呢 每个segment都能被点击,相当于集成了多个button 通常我们会点击不同的segment来切换不同的view 那么它实现了一个什么效果呢,我们先看下图: 这就是我们实现的效果,这里家具.灯饰等等每一项就是一个按钮,点击会触发不同事件或跳转到不同页面 那么怎么实现这一效果能,只需要简单几句代码: //先生成存放标题的数据 NSArray *array = [NSArray arrayWithOb

Navigator导航器

import React, { Component } from 'react';import { Platform, StyleSheet, Text, View, Navigator, TouchableOpacity } from 'react-native'; /** 在ReactNative中,有两个实现导航功能的组件:Navigator和NavigatorIOS* Navigator 同支持android和ios ; NavgatorIOS支持ios* NavigatorIOS 相对

[Swift通天遁地]九、拔剑吧-(3)创建多种自定义Segment分段样式的控件

本文将演示创建多种自定义Segment分段样式的控件. 首先确保已经安装了所需的第三方类库.双击查看安装配置文件[Podfile] 1 platform :ios, '12.0' 2 use_frameworks! 3 4 target 'DemoApp' do 5 source 'https://github.com/CocoaPods/Specs.git' 6 pod 'PagingMenuController' 7 end 根据配置文件中的相关设置,安装第三方类库. 安装完成之后,双击打开

[Swift通天遁地]九、拔剑吧-(4)使用开源类库创建可滑动的Segment分段控件

本文将演示创建多种自定义Segment分段样式的控件. 首先确保已经安装了所需的第三方类库.双击查看安装配置文件[Podfile] 1 platform :ios, ‘12.0’ 2 use_frameworks! 3 4 target 'DemoApp' do 5 source 'https://github.com/CocoaPods/Specs.git' 6 pod 'TwicketSegmentedControl' 7 end 根据配置文件中的相关设置,安装第三方类库. 安装完成之后,双

OWIN轻量型框架介绍

OWIN轻量型框架介绍 阅读目录 引言 框架的特色 如何启动 各项功能 静态路由的3种写法 伪静态路由的支持 处理Form表单提交的文件 流式处理Post请求的数据 多种请求类型自动识别 响应处理 请求响应上下文 自定义默认处理函数 内置各种便捷函数 复合类型的请求处理 框架的扩展 静态内容的支持 跨域Post的支持 基础类型继承灵活处理 尾声 回到顶部 引言 什么是OWIN,我就不介绍了,请自行搜索,这里主要是介绍自行开发的OWIN框架的特点和用法.由于.NET的web框架都比较庞大,导致性能