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

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];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值