223 lines
9.1 KiB
Objective-C
223 lines
9.1 KiB
Objective-C
//
|
||
// DDMyInformationProfileViewController.m
|
||
// DingDangApp
|
||
//
|
||
// Created by apple on 2023/6/28.
|
||
//
|
||
|
||
#import "DDMyInformationProfileViewController.h"
|
||
|
||
@interface DDMyInformationProfileViewController ()
|
||
|
||
@end
|
||
|
||
@implementation DDMyInformationProfileViewController
|
||
|
||
- (UIButton *)myIDBtn{
|
||
if (!_myIDBtn) {
|
||
_myIDBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||
[_myIDBtn setTitle:@"ID:0" forState:UIControlStateNormal];
|
||
[_myIDBtn setTitleColor:[UIColor jk_colorWithHexString:@"#333333"] forState:UIControlStateNormal];
|
||
_myIDBtn.titleLabel.font = [UIFont systemFontOfSize:12];
|
||
_myIDBtn.backgroundColor = [UIColor jk_colorWithHexString:@"#F7F7F8"];
|
||
_myIDBtn.layer.masksToBounds = YES;
|
||
_myIDBtn.layer.cornerRadius = 8;
|
||
[_myIDBtn addTarget:self action:@selector(myIDBtnClick) forControlEvents:UIControlEventTouchUpInside];
|
||
}
|
||
return _myIDBtn;
|
||
}
|
||
- (UIButton *)myAgeBtn{
|
||
if (!_myAgeBtn) {
|
||
_myAgeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||
[_myAgeBtn setTitle:@"0岁" forState:UIControlStateNormal];
|
||
[_myAgeBtn setTitleColor:[UIColor jk_colorWithHexString:@"#333333"] forState:UIControlStateNormal];
|
||
_myAgeBtn.titleLabel.font = [UIFont systemFontOfSize:12];
|
||
_myAgeBtn.backgroundColor = [UIColor jk_colorWithHexString:@"#F7EBFF"];
|
||
_myAgeBtn.layer.masksToBounds = YES;
|
||
_myAgeBtn.layer.cornerRadius = 8;
|
||
}
|
||
return _myAgeBtn;
|
||
}
|
||
- (UIButton *)myConsBtn{
|
||
if (!_myConsBtn) {
|
||
_myConsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||
[_myConsBtn setTitle:@"星座" forState:UIControlStateNormal];
|
||
[_myConsBtn setTitleColor:[UIColor jk_colorWithHexString:@"#333333"] forState:UIControlStateNormal];
|
||
_myConsBtn.titleLabel.font = [UIFont systemFontOfSize:12];
|
||
_myConsBtn.backgroundColor = [UIColor jk_colorWithHexString:@"#EAF0FF"];
|
||
|
||
_myConsBtn.layer.masksToBounds = YES;
|
||
_myConsBtn.layer.cornerRadius = 8;
|
||
}
|
||
return _myConsBtn;
|
||
}
|
||
- (UIView *)myContentBgView{
|
||
if (!_myContentBgView) {
|
||
_myContentBgView = [[UIView alloc] init];
|
||
_myContentBgView.backgroundColor = [UIColor jk_colorWithHexString:@"#F7F8F9"];
|
||
_myContentBgView.layer.masksToBounds = YES;
|
||
_myContentBgView.layer.cornerRadius = 8;
|
||
}
|
||
return _myContentBgView;
|
||
}
|
||
- (UILabel *)titleLabel{
|
||
if (!_titleLabel) {
|
||
_titleLabel = [[UILabel alloc] init];
|
||
_titleLabel.text = @"个性签名:";
|
||
_titleLabel.textColor = [UIColor jk_colorWithHexString:@"#666666"];
|
||
_titleLabel.font = [UIFont systemFontOfSize:12];
|
||
}
|
||
return _titleLabel;
|
||
}
|
||
- (UILabel *)myContentLabel{
|
||
if (!_myContentLabel) {
|
||
_myContentLabel = [[UILabel alloc] init];
|
||
_myContentLabel.text = @"高冷的ta不喜欢留签名";
|
||
_myContentLabel.textColor = [UIColor jk_colorWithHexString:@"#666666"];
|
||
_myContentLabel.font = [UIFont systemFontOfSize:12];
|
||
_myContentLabel.numberOfLines = 0;
|
||
}
|
||
return _myContentLabel;
|
||
}
|
||
- (void)viewDidLoad {
|
||
[super viewDidLoad];
|
||
// Do any additional setup after loading the view.
|
||
[self.view addSubview:self.myIDBtn];
|
||
[self.myIDBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.top.mas_equalTo(self.view).mas_offset(20);
|
||
make.left.mas_equalTo(self.view).mas_offset(16);
|
||
make.size.mas_equalTo(CGSizeMake(120, 28));
|
||
}];
|
||
|
||
[self.view addSubview:self.myAgeBtn];
|
||
[self.myAgeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.centerY.mas_equalTo(self.myIDBtn).mas_offset(0);
|
||
make.left.mas_equalTo(self.myIDBtn.mas_right).mas_offset(12);
|
||
make.size.mas_equalTo(CGSizeMake(52, 28));
|
||
}];
|
||
|
||
[self.view addSubview:self.myConsBtn];
|
||
[self.myConsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.centerY.mas_equalTo(self.myIDBtn).mas_offset(0);
|
||
make.left.mas_equalTo(self.myAgeBtn.mas_right).mas_offset(12);
|
||
make.size.mas_equalTo(CGSizeMake(60, 28));
|
||
}];
|
||
|
||
[self.view addSubview:self.myContentBgView];
|
||
[self.myContentBgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.width.mas_equalTo(kWidth-36);
|
||
make.left.mas_equalTo(self.view.mas_left).mas_offset(16);
|
||
make.top.mas_equalTo(self.myConsBtn.mas_bottom).mas_offset(12);
|
||
}];
|
||
|
||
[self.view addSubview:self.titleLabel];
|
||
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.left.mas_equalTo(self.myContentBgView.mas_left).mas_offset(12);
|
||
make.top.mas_equalTo(self.myContentBgView.mas_top).mas_offset(12);
|
||
}];
|
||
|
||
[self.view addSubview:self.myContentLabel];
|
||
[self.myContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.left.mas_equalTo(self.myContentBgView.mas_left).mas_offset(12);
|
||
make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(7);
|
||
make.bottom.mas_equalTo(self.myContentBgView.mas_bottom).mas_offset(-12);
|
||
}];
|
||
}
|
||
- (void)myIDBtnClick{
|
||
if (![ToolsObject IsNullWithObject:@(self.personModel.erbanNo).stringValue]) {
|
||
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
|
||
pasteboard.string = @(self.personModel.erbanNo).stringValue;
|
||
[self.view jk_makeToast:@"已复制ID到剪切板!"];
|
||
}
|
||
}
|
||
- (void)setPersonModel:(UserInfoModel *)personModel{
|
||
_personModel = personModel;
|
||
[self.myIDBtn setTitle:[NSString stringWithFormat:@"ID:%@",@(personModel.erbanNo)] forState:UIControlStateNormal];
|
||
[self.myIDBtn setImage:[UIImage imageNamed:@"myinfo_21"] forState:UIControlStateNormal];
|
||
[self.myIDBtn jk_setImagePosition:LXMImagePositionRight spacing:4];
|
||
[self.myAgeBtn setTitle:[NSString stringWithFormat:@"%@岁",[self dd_getUserAge:_personModel.birth]] forState:UIControlStateNormal];
|
||
[self.myConsBtn setTitle:[self dd_getConstellationWithMonth:_personModel.birth] forState:UIControlStateNormal];
|
||
self.myContentLabel.text = personModel.userDesc ?:@"这个人很懒,没什么签名~";
|
||
|
||
}
|
||
-(NSInteger) dd_getMonth:(long )time
|
||
{
|
||
NSDate *date = [NSDate dateWithTimeIntervalSince1970:time/1000];
|
||
NSCalendar* calendar = [NSCalendar currentCalendar];
|
||
NSDateComponents* components = [calendar components:NSCalendarUnitMonth fromDate:date];
|
||
NSInteger month = components.month;
|
||
return month;
|
||
}
|
||
|
||
- (NSInteger) dd_getDay:(long) time
|
||
{
|
||
NSDate *date = [NSDate dateWithTimeIntervalSince1970:time/1000];
|
||
NSCalendar* calendar = [NSCalendar currentCalendar];
|
||
NSDateComponents* components = [calendar components:NSCalendarUnitDay fromDate:date];
|
||
NSInteger day = components.day;
|
||
return day;
|
||
}
|
||
|
||
- (NSString *)dd_getConstellationWithMonth:(long)time
|
||
{
|
||
NSString *astroString = @"魔羯水瓶双鱼白羊金牛双子巨蟹狮子处女天秤天蝎射手魔羯";
|
||
NSString *astroFormat = @"102123444543";
|
||
NSString *result;
|
||
|
||
NSInteger month = [self dd_getMonth:time];
|
||
NSInteger day = [self dd_getDay:time];
|
||
|
||
if (month<1 || month>12 || day<1 || day>31){
|
||
return @"错误日期格式!";
|
||
}
|
||
|
||
if(month==2 && day>29)
|
||
{
|
||
return @"错误日期格式!!";
|
||
}else if(month==4 || month==6 || month==9 || month==11) {
|
||
if (day>30) {
|
||
return @"错误日期格式!!!";
|
||
}
|
||
}
|
||
|
||
result=[NSString stringWithFormat:@"%@",[astroString substringWithRange:NSMakeRange(month*2-(day < [[astroFormat substringWithRange:NSMakeRange((month-1), 1)] intValue] - (-19))*2,2)]];
|
||
|
||
return [NSString stringWithFormat:@"%@座",result];
|
||
}
|
||
- (NSString *)dd_getUserAge:(long)time {
|
||
NSDate *date = [NSDate dateWithTimeIntervalSince1970:time/1000];
|
||
NSCalendar *birthCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierISO8601];
|
||
NSDateComponents *birthCompomemts = [birthCalendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitWeekday | NSCalendarUnitDay fromDate:date];
|
||
NSInteger year = birthCompomemts.year;
|
||
NSInteger month = birthCompomemts.month;
|
||
NSInteger day = birthCompomemts.day;
|
||
NSLog(@"出生于%ld年%ld月%ld日", year, month, day);
|
||
|
||
NSDate *nowDate = [NSDate date];
|
||
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierISO8601];
|
||
NSDateComponents *compomemts = [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitWeekday | NSCalendarUnitDay fromDate:nowDate];
|
||
NSInteger nowYear = compomemts.year;
|
||
NSInteger nowMonth = compomemts.month;
|
||
NSInteger nowDay = compomemts.day;
|
||
NSLog(@"今天是%ld年%ld月%ld日", nowYear, nowMonth, nowDay);
|
||
|
||
// 计算年龄
|
||
NSInteger userAge = nowYear - year - 1;
|
||
if ((nowMonth > month) || (nowMonth == month && nowDay >= day)) {
|
||
userAge++;
|
||
}
|
||
NSLog(@"用户年龄是%ld",userAge);
|
||
return [NSString stringWithFormat:@"%ld", userAge];
|
||
}
|
||
/*
|
||
#pragma mark - Navigation
|
||
|
||
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
||
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
||
// Get the new view controller using [segue destinationViewController].
|
||
// Pass the selected object to the new view controller.
|
||
}
|
||
*/
|
||
|
||
@end
|