您的位置:首页 > 产品设计 > UI/UE

Ios中导航栏和标签栏的结合以及UIButton、UILabel的使用

2017-06-05 10:08 429 查看

ios中导航栏和标签栏的结合以及UIButton、UILabel的使用

导航栏和标签栏的结合

现在ios的app界面通常都是由导航栏和标签栏相结合构成的,这是一种多层包装的模式,就是初始化一个TabBar作为界面的根视图控制器,这个TabBar包含了几个Navigation,每个Navigation再包含各自的ViewController,代码如下:

//初始化标签栏并设置标签栏为根视图
CHYTabbarViewController *tabbarVC = [[CHYTabbarViewController alloc] init];
self.window.rootViewController = tabbarVC;

//初始化两个界面控制器
CHYHomeViewController *homeVC = [[CHYHomeViewController alloc] init];//首页
CHYConnectViewController *connectVC = [[CHYConnectViewController alloc] init];//收藏

//用导航控制器包装界面控制器
UINavigationController *homeNav = [[UINavigationController alloc] initWithRootViewController:homeVC];
UINavigationController *connectNav = [[UINavigationController alloc] initWithRootViewController:connectVC];

//将导航栏控制器添加到TabBar当中
[self addChildViewController:homeNav];
[self addChildViewController:connectNav];


Xcode当中有自带的标签栏的样式,代码如下:

//为首页设计系统自带的标签栏风格
homeVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:1];


UIButton的使用

在ios界面效果中,点击按钮后,我们可以进行界面的跳转,也可以改变按钮的状态,按钮的点击效果在方法clikBtn当中写出,代码如下:

//定义收藏按钮
self.collectBtn = [[UIButton alloc] initWithFrame:CGRectMake((SCREENWIDTH-100)/2, 540, 200, 50)];//按钮的位置
[self.collectBtn setTitle:@"收藏" forState:UIControlStateNormal];
[self.collectBtn setTitleColor : [UIColor blueColor] forState : UIControlStateNormal];
[self.collectBtn addTarget:self action:@selector(clikBtn) forControlEvents : UIControlEventTouchUpInside];
[self.view addSubview:self.collectBtn];

}//将按钮显示在界面中

- (void)clikBtn {
[self.collectBtn setTitle:@"已收藏" forState:UIControlStateNormal];
}//点击按钮后,变为已收藏


UILabel的使用

在app界面中,文本无疑是经常被使用的,具体代码如下:

UILabel *label=[[UILabel alloc]init];
label.frame = CGRectMake(12 , 200 , SCREENWIDTH - 24 , 20);
label.text=@"这是通讯录";
label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:label];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐