// // DoctorHomePageDetailVC.m // QinghaiProject // // Created by Apple on 2024/8/22. // #import "DoctorHomePageDetailVC.h" #import "ChatDoctorInfoModel.h" @interface DoctorHomePageDetailVC () @property (nonatomic, strong) UIImageView * heardImg; @property (nonatomic, strong) UILabel * titleLabel; @property (nonatomic, strong) UILabel * label; @property (nonatomic, strong) UILabel * namelabel; @property (nonatomic, strong) UIScrollView *scrollView; @property (nonatomic, strong) UIView *contentView; @end @implementation DoctorHomePageDetailVC - (void)viewDidLoad { [super viewDidLoad]; self.isHidenNaviBar = false; self.view.backgroundColor = UIColorHex(#EEEEEE); self.navigationItem.title = @"全科医生主页"; [self createUI]; [self getSmllHelpDetailInfo]; // Do any additional setup after loading the view. } - (void)createUI { UIView * topView = [[UIView alloc] init]; topView.backgroundColor = UIColorHex(#21BEBD); [self.view addSubview:topView]; [topView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.mas_offset(0); make.height.mas_offset(kRealValue(170)); }]; self.heardImg = [[UIImageView alloc] init]; self.heardImg.layer.masksToBounds = true; self.heardImg.layer.cornerRadius = 30; self.heardImg.image = [UIImage imageNamed:@"nomalDetailHeard"]; [topView addSubview:self.heardImg]; [self.heardImg mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_offset(10); make.left.mas_offset(17); make.width.height.mas_offset(60); }]; self.titleLabel= [[UILabel alloc] init]; self.titleLabel.font = BOLDSYSTEMFONT(21); self.titleLabel.textColor = KWhiteColor; self.titleLabel.text = @"小助手"; self.titleLabel.textAlignment = NSTextAlignmentLeft; [topView addSubview:self.titleLabel]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_offset(26); make.left.mas_equalTo(self.heardImg.mas_right).offset(19); make.right.mas_offset(-20); }]; // 创建并配置 UIScrollView self.scrollView = [[UIScrollView alloc] init]; self.scrollView.backgroundColor = [UIColor whiteColor]; self.scrollView.layer.cornerRadius = 10; self.scrollView.layer.masksToBounds = YES; [self.view addSubview:self.scrollView]; // 创建容器视图 self.contentView = [[UIView alloc] init]; [self.scrollView addSubview:self.contentView]; // 设置容器视图的约束 [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.scrollView); make.width.equalTo(self.scrollView.mas_width); }]; self.namelabel= [[UILabel alloc] init]; self.namelabel.font = BOLDSYSTEMFONT(16); self.namelabel.text = @"全科医生简介"; self.namelabel.textColor = UIColorHex(#333333); self.namelabel.textAlignment = NSTextAlignmentLeft; [self.contentView addSubview:self.namelabel]; // 创建并配置 UILabel self.label = [[UILabel alloc] init]; self.label.numberOfLines = 0; // 多行显示 self.label.textColor = UIColorHex(#333333); // 将 UILabel 添加到容器视图 [self.contentView addSubview:self.label]; // 设置 UIScrollView 和 contentView 的约束 [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view.mas_top).offset(93); make.left.equalTo(self.view.mas_left).offset(15); make.right.equalTo(self.view.mas_right).offset(-15); }]; [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.scrollView); make.width.equalTo(self.scrollView.mas_width); // contentView 的宽度等于 scrollView 的宽度 make.bottom.equalTo(self.label.mas_bottom).offset(20); // contentView 底部与 label 的底部加 20 像素 }]; [self.namelabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView.mas_top).offset(20); make.left.equalTo(self.contentView.mas_left).offset(15); make.right.equalTo(self.contentView.mas_right).offset(-15); }]; // 设置 UILabel 的约束 [self.label mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView.mas_top).offset(53); make.left.equalTo(self.contentView.mas_left).offset(20); make.right.equalTo(self.contentView.mas_right).offset(-20); make.bottom.equalTo(self.contentView.mas_bottom).offset(-20); // 留出底部空间 }]; [self updateLabelText:@"--"]; } - (void)updateLabelText:(NSString *)text { NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.lineSpacing = 10; // 设置行间距 NSDictionary *attributes = @{ NSParagraphStyleAttributeName: paragraphStyle, NSFontAttributeName:[UIFont systemFontOfSize:15 weight:UIFontWeightMedium] }; NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:text attributes:attributes]; self.label.attributedText = attributedText; // 强制布局更新,确保 UIScrollView 正确计算 contentSize [self.view layoutIfNeeded]; // 计算 contentView 高度并更新 UIScrollView 的高度 CGSize contentSize = [self.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]; [self.scrollView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(contentSize.height); }]; // 重新布局 [self.view layoutIfNeeded]; } - (void)getSmllHelpDetailInfo{ NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init]; [parmDic setObject:self.userID forKey:@"helpId"]; JKCQAPI * endApi = [[JKCQAPI alloc] init:self tag:@"Detail" NeedToken:@""]; [endApi GetSmllHelpDetail:parmDic]; } #pragma mark:网络请求 - (void)Failed:(NSString*)message tag:(NSString*)tag { [self showMBProgressHUDOnlyWithString:message]; [self hiddenAllMBProgressHUD]; } - (void)Sucess:(id)response tag:(NSString*)tag { if ([tag isEqualToString:@"Detail"]) { NSDictionary * dic = response; ChatDoctorInfoModel * model = [ChatDoctorInfoModel modelWithDictionary:dic]; self.titleLabel.text = [NSString stringWithFormat:@"%@",model.userName]; NSString * photo = [NSString stringWithFormat:@"%@%@",ResourceAddress,model.faceUrl]; NSString * str1 = @"\\"; photo = [ photo stringByReplacingOccurrencesOfString:str1 withString:@"/"]; NSString *encodedString3 = CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef) photo, (CFStringRef)@"!$&'()*+,-./:;=?@_~%#[]", NULL, kCFStringEncodingUTF8)); [self.heardImg sd_setImageWithURL:[NSURL URLWithString:encodedString3] placeholderImage:[UIImage imageNamed:@"nomalDetailHeard"]]; [self updateLabelText:[NSString stringWithFormat:@"%@",model.memo]]; } } /* #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