self.navigationController.navigationBarHidden = NO; 解释代码
时间: 2024-01-24 11:20:39 浏览: 23
这段代码是用于 iOS 开发中的导航栏控制器中的属性设置。具体来说,`self` 是当前视图控制器,`navigationController` 是当前视图控制器所在的导航栏控制器对象。
`navigationBarHidden` 是一个布尔类型的属性,用于控制导航栏是否隐藏。当设置为 `NO` 时,导航栏将会显示出来。
因此,这段代码的作用就是将当前视图控制器所在的导航栏控制器的导航栏显示出来。
相关问题
[self.navigationController setNavigationBarHidden:NO animated:YES]状态栏为什么也会显示
在iOS中,状态栏和导航栏是两个不同的控件。设置导航栏的隐藏状态并不会影响状态栏的显示。如果你想要隐藏状态栏,可以在控制器中添加以下代码:
```
- (BOOL)prefersStatusBarHidden {
return YES;
}
```
这样就可以隐藏状态栏了。如果你想要显示状态栏,只需要将返回值改为NO即可。
Objective-c纯代码实现签到界面
Objective-C 纯代码实现签到界面的步骤如下:
1. 创建一个 UIViewController。
```
#import <UIKit/UIKit.h>
@interface SignInViewController : UIViewController
@end
```
2. 在 UIViewController 中添加需要的 UI 元素。
```
@interface SignInViewController ()
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *descriptionLabel;
@property (nonatomic, strong) UILabel *dateLabel;
@property (nonatomic, strong) UIButton *signInButton;
@end
@implementation SignInViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 30)];
self.titleLabel.textAlignment = NSTextAlignmentCenter;
self.titleLabel.text = @"签到";
[self.view addSubview:self.titleLabel];
self.descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 150, self.view.frame.size.width, 30)];
self.descriptionLabel.textAlignment = NSTextAlignmentCenter;
self.descriptionLabel.text = @"签到可以获得积分哦";
[self.view addSubview:self.descriptionLabel];
self.dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 200, self.view.frame.size.width, 30)];
self.dateLabel.textAlignment = NSTextAlignmentCenter;
self.dateLabel.text = [self getCurrentDate];
[self.view addSubview:self.dateLabel];
self.signInButton = [[UIButton alloc] initWithFrame:CGRectMake((self.view.frame.size.width - 100) / 2, 250, 100, 50)];
[self.signInButton setTitle:@"签到" forState:UIControlStateNormal];
[self.signInButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[self.signInButton addTarget:self action:@selector(signInButtonAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.signInButton];
}
- (NSString *)getCurrentDate {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd"];
NSString *currentDate = [formatter stringFromDate:[NSDate date]];
return currentDate;
}
- (void)signInButtonAction {
// 处理签到逻辑
}
@end
```
3. 在需要的地方创建 SignInViewController 并展示。
```
SignInViewController *signInViewController = [[SignInViewController alloc] init];
[self.navigationController pushViewController:signInViewController animated:YES];
```
以上就是 Objective-C 纯代码实现签到界面的步骤。