Objective-c纯代码实现签到界面
时间: 2023-12-24 08:05:06 浏览: 74
以下是Objective-C纯代码实现签到界面的示例代码:
```objective-c
#import "CheckInViewController.h"
@interface CheckInViewController ()
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *checkInButton;
@end
@implementation CheckInViewController
- (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.text = @"今日签到";
self.titleLabel.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:self.titleLabel];
// 添加签到按钮
self.checkInButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 150, 50)];
self.checkInButton.center = self.view.center;
[self.checkInButton setTitle:@"签到" forState:UIControlStateNormal];
[self.checkInButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.checkInButton setBackgroundColor:[UIColor blueColor]];
[self.checkInButton addTarget:self action:@selector(checkInButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.checkInButton];
}
- (void)checkInButtonClicked {
// 处理签到逻辑
NSLog(@"签到成功!");
}
@end
```
这段代码中,我们创建了一个`CheckInViewController`类,其中包括`titleLabel`和`checkInButton`两个控件。在`viewDidLoad`方法中,我们设置了背景颜色,并添加了标题和签到按钮。当用户点击签到按钮时,我们在`checkInButtonClicked`方法中处理签到逻辑,并在控制台输出签到成功的日志。
阅读全文