MPCHeadView.m 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. //
  2. // MPCHeadView.m
  3. // BuguLive
  4. //
  5. // Created by 丁凯 on 2017/8/24.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "MPCHeadView.h"
  9. #import "userPageModel.h"
  10. #import "BGSystemMacro.h"
  11. #import "UserHomeModel.h"
  12. #import "HPContributionCell.h"
  13. @interface MPCHeadView ()<UITableViewDelegate,UITableViewDataSource>
  14. @property(nonatomic, strong) UITableView *tableView;
  15. @property(nonatomic, strong) NSMutableArray *imageArray;
  16. @property(nonatomic, strong) UIImageView *nobleImageView;
  17. @end
  18. @implementation MPCHeadView
  19. - (instancetype)initWithFrame:(CGRect)frame andHeadType:(int)headType
  20. {
  21. self = [super initWithFrame:frame];
  22. if (self)
  23. {
  24. [self creatMyViewWithType:headType];
  25. self.backgroundColor = kClearColor;
  26. }
  27. return self;
  28. }
  29. static UIView * extracted(MPCHeadView *object) {
  30. return object.nameView;
  31. }
  32. - (void)creatMyViewWithType:(int)headType
  33. {
  34. //底部透明图片
  35. self.clearImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 250)];
  36. self.clearImgView.userInteractionEnabled = YES;
  37. self.clearImgView.contentMode = UIViewContentModeScaleAspectFill;
  38. self.clearImgView.clipsToBounds = YES;
  39. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickHeadImg:)];
  40. // [self.clearImgView addGestureRecognizer:tap];
  41. [self addSubview:self.clearImgView];
  42. //透明的view
  43. self.clearView = [[UIImageView alloc]initWithFrame:CGRectMake(kRealValue(6), 156, kScreenW - kRealValue(6) * 2, kRealValue(184))];
  44. self.clearView.image = [UIImage imageNamed:@"bogo_home_person_Top_BgImage"];
  45. self.clearView.backgroundColor = kClearColor;
  46. // self.clearView.layer.cornerRadius = 10;
  47. // self.clearView.layer.masksToBounds = YES;
  48. self.clearView.userInteractionEnabled = YES;
  49. // [[UIColor whiteColor] colorWithAlphaComponent:0.85];
  50. [self addSubview:self.clearView];
  51. // 返回
  52. self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
  53. self.backButton.frame = CGRectMake(0,kStatusBarHeight, 50,44);
  54. self.backButton.backgroundColor = [UIColor clearColor];
  55. self.backButton.hidden = YES;
  56. if (headType == 1)
  57. {
  58. [self.backButton setImage:[UIImage imageNamed:@"fw_me_search"] forState:UIControlStateNormal];
  59. self.backButton.hidden = YES;
  60. }else if (headType == 2)
  61. {
  62. [self.backButton setImage:[UIImage imageNamed:@"ac_auction_back"] forState:UIControlStateNormal];
  63. }
  64. self.backButton.tag = 100;
  65. [self.backButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  66. [self addSubview:self.backButton];
  67. //谁的主页
  68. self.outLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenW/2-90, kStatusBarHeight, 180,44)];
  69. self.outLabel.textColor = [UIColor blackColor];
  70. self.outLabel.font = [UIFont systemFontOfSize:16];
  71. self.outLabel.textAlignment = NSTextAlignmentCenter;
  72. if (headType == 1)
  73. {
  74. self.outLabel.text = ASLocalizedString(@"我的");
  75. }
  76. [self addSubview:self.outLabel];
  77. //直播
  78. self.messageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  79. self.messageBtn.tag = 101;
  80. [self.messageBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
  81. self.messageBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  82. self.messageBtn.hidden = YES;
  83. // self.messageBtn.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
  84. [self.messageBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  85. [self addSubview:self.messageBtn];
  86. if (headType == 1)
  87. {
  88. self.messageBtn.frame = CGRectMake(kScreenW-40,kStatusBarHeight+(44-28)/2,30,28);
  89. // 设置角标
  90. [self initBadgeBtn:self.messageBtn];
  91. [self.messageBtn setImage:[UIImage imageNamed:@"fw_me_news"] forState:UIControlStateNormal];
  92. self.messageBtn.hidden = YES;
  93. }else
  94. {
  95. self.messageBtn.frame = CGRectMake(kScreenW-60,kStatusBarHeight,50,44);
  96. }
  97. //头像
  98. self.headImgView = [[UIImageView alloc]init];
  99. self.headImgView.frame = CGRectMake(kScreenW/2-85*kScaleWidth/2,85,85*kScaleWidth, 85*kScaleWidth);
  100. self.headImgView.hidden = YES;
  101. // self.headImgView.layer.borderWidth = 2;
  102. self.headImgView.image = kDefaultPreloadHeadImg;
  103. self.headImgView.contentMode = UIViewContentModeScaleAspectFit;
  104. // self.headImgView.layer.borderColor = kBlackColor.CGColor;
  105. self.headImgView.layer.cornerRadius = 85*kScaleWidth/2;
  106. self.headImgView.layer.masksToBounds = YES;
  107. self.headImgView.userInteractionEnabled = YES;
  108. UITapGestureRecognizer *tapHead = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickHeadImg:)];
  109. [self.headImgView addGestureRecognizer:tapHead];
  110. [self addSubview:self.headImgView];
  111. //认证图标
  112. self.vImgView = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.headImgView.frame)-kViconWidthOrHeight2*1.3, CGRectGetMaxY(self.headImgView.frame)-kViconWidthOrHeight2*1.3, kViconWidthOrHeight2, kViconWidthOrHeight2)];
  113. [self addSubview:self.vImgView];
  114. self.vImgView.hidden = YES;
  115. //头像
  116. self.headImgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  117. self.headImgBtn.frame = CGRectMake(kScreenW/2-85*kScaleWidth/2,85,85*kScaleWidth, 85*kScaleWidth);
  118. self.headImgBtn.tag = 102;
  119. self.headImgBtn.backgroundColor = kClearColor;
  120. self.headImgBtn.hidden = YES;
  121. [self.headImgBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  122. [self addSubview:self.headImgBtn];
  123. //名字 性别 等级
  124. self.nameView = [[UIView alloc]initWithFrame:CGRectMake(kRealValue(26), kRealValue(15) , self.clearView.width / 2, 30)];
  125. self.nameView.backgroundColor = kClearColor;
  126. [self.clearView addSubview:self.nameView];
  127. self.nameLabel = [[UILabel alloc]init];
  128. self.nameLabel.textColor = kBlackColor;
  129. self.nameLabel.font = [UIFont systemFontOfSize:16];
  130. self.nameLabel.textAlignment = NSTextAlignmentLeft;
  131. [extracted(self) addSubview:self.nameLabel];
  132. self.livingBtn = [[UIButton alloc]initWithFrame:CGRectMake(self.nameLabel.right + 10, 0, 60, 16)];
  133. self.livingBtn.centerY = self.nameLabel.centerY;
  134. [self.livingBtn setImage:[UIImage imageNamed:@"回播中"] forState:UIControlStateNormal];
  135. [self.livingBtn setImage:[UIImage imageNamed:@"直播中"] forState:UIControlStateSelected];
  136. [self.livingBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  137. self.livingBtn.tag = 101;
  138. [extracted(self) addSubview:self.livingBtn];
  139. self.vipImgView = [[UIImageView alloc]init];
  140. self.vipImgView.image = [UIImage imageNamed:@"mg_new_vip_icon"];
  141. [self.clearView addSubview:self.vipImgView];
  142. self.nobleImageView = [[UIImageView alloc]init];
  143. [self.clearView addSubview:self.nobleImageView];
  144. self.sexImgView = [[UIImageView alloc]init];
  145. [self.clearView addSubview:self.sexImgView];
  146. self.rankImgView = [[UIImageView alloc]init];
  147. [self.clearView addSubview:self.rankImgView];
  148. self.concertBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  149. // [self.concertBtn setTitle:ASLocalizedString(@"关注")forState:UIControlStateNormal];
  150. // [self.concertBtn setImage:[UIImage imageNamed:@"me_new_head_concertTitle"] forState:UIControlStateNormal];
  151. [self.concertBtn addTarget:self action:@selector(clickAttention:) forControlEvents:UIControlEventTouchUpInside];
  152. [self.concertBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
  153. self.concertBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  154. [self.concertBtn setBackgroundImage:[UIImage imageNamed:@"bogo_home_person_Concert_normal"] forState:UIControlStateNormal];//mg_new_list_concert
  155. //
  156. self.concertBtn.frame = CGRectMake(self.clearView.width - 10 - 53 - 10, 0, 53, 22);
  157. self.concertBtn.centerY = self.nameView.centerY;
  158. self.concertBtn.imagePosition = QMUIButtonImagePositionLeft;
  159. self.concertBtn.spacingBetweenImageAndTitle = 2;
  160. self.concertBtn.hidden = YES;
  161. [self.clearView addSubview:self.concertBtn];
  162. if (headType == 1)
  163. {
  164. self.editBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  165. [self.editBtn setImage:[UIImage imageNamed:@"fw_me_bianji"] forState:UIControlStateNormal];
  166. self.editBtn.tag = 103;
  167. [self.editBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  168. [self.nameView addSubview:self.editBtn];
  169. }else
  170. {
  171. self.messageBtn.frame = CGRectMake(kScreenW - 60,kStatusBarHeight,50,44);
  172. }
  173. //签名
  174. self.signatureLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(self.nameView.frame), kScreenW,21)];
  175. self.signatureLabel.textAlignment = NSTextAlignmentCenter;
  176. self.signatureLabel.textColor = kBlackColor;
  177. self.signatureLabel.font = [UIFont systemFontOfSize:12];
  178. self.signatureLabel.hidden = YES;
  179. [self.clearView addSubview:self.signatureLabel];
  180. //账号
  181. self.accountLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.nameView.left,CGRectGetMaxY(self.signatureLabel.frame), kScreenW,21)];
  182. self.accountLabel.textColor = kBlackColor;
  183. self.accountLabel.font = [UIFont systemFontOfSize:12];
  184. self.accountLabel.textAlignment = NSTextAlignmentLeft;
  185. [self.clearView addSubview:self.accountLabel];
  186. // //认证和认证的图标
  187. self.certificateBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  188. [self.certificateBtn setTitle:ASLocalizedString(@"身份认证")forState:UIControlStateNormal];
  189. self.certificateBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  190. // [self.certificateBtn setImagePosition:QMUIButtonImagePositionLeft];
  191. [self.certificateBtn setImage:[UIImage imageNamed:@"mg_dt_near_cert"] forState:UIControlStateNormal];
  192. [self.certificateBtn setTitleColor:[UIColor colorWithHexString:@"#04AEFB"] forState:UIControlStateNormal];
  193. self.certificateBtn.userInteractionEnabled = NO;
  194. // [self.certificateBtn setBackgroundImage:[UIImage imageNamed:@"mg_people_certBgImView"] forState:UIControlStateNormal];
  195. self.certificateBtn.titleLabel.font = [UIFont systemFontOfSize:10];
  196. self.certificateBtn.spacingBetweenImageAndTitle = 2;
  197. self.certificateBtn.frame = CGRectMake(0, 0, kRealValue(80), 13);
  198. [self.clearView addSubview:self.certificateBtn];
  199. self.shopBtn = [[UIButton alloc]initWithFrame:CGRectMake(self.clearView.width - 75 - 10, self.clearView.top - 35, 70, 70)];
  200. NSLog(@"%@",self.shopBtn);
  201. [self.shopBtn setImage:[UIImage imageNamed:@"my_商品橱窗"] forState:UIControlStateNormal];
  202. self.shopBtn.tag = 114;
  203. self.shopBtn.hidden = YES;
  204. [self.shopBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  205. [self addSubview:self.shopBtn];
  206. //底部的view
  207. self.bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.clearView.frame),kScreenW,62)];
  208. self.bottomView.backgroundColor = kBackGroundColor;
  209. self.bottomView.hidden = YES;
  210. [self addSubview:self.bottomView];
  211. @autoreleasepool
  212. {
  213. self.itemView = [[UIView alloc]initWithFrame:CGRectMake(0, self.nameView.bottom, kScreenW, 70)];
  214. // self.itemView.layer.cornerRadius = 3;
  215. self.itemView.layer.masksToBounds = YES;
  216. self.itemView.backgroundColor = kClearColor;
  217. [self.clearView addSubview:self.itemView];
  218. NSArray *array;
  219. if (headType == 1)
  220. {
  221. array = @[ASLocalizedString(@"回播"),ASLocalizedString(@"小视频"),ASLocalizedString(@"关注"),ASLocalizedString(@"粉丝"),];
  222. }else if (headType == 2)
  223. {
  224. array = @[ASLocalizedString(@"送出"),ASLocalizedString(@"关注"),ASLocalizedString(@"粉丝"),];
  225. }
  226. CGFloat labelW = kScreenW / 3;
  227. // (kScreenW-20-array.count-1)/array.count;
  228. for (int i = 0; i < array.count; i++)
  229. {
  230. UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake((labelW+1)*i,self.itemView.height/2 - 20, labelW, 25)];
  231. nameLabel.tag = array.count +i;
  232. nameLabel.text = array[i];
  233. nameLabel.textColor = [UIColor colorWithHex:0x333333];
  234. nameLabel.textAlignment = NSTextAlignmentCenter;
  235. nameLabel.font = [UIFont systemFontOfSize:12];
  236. [self.itemView addSubview:nameLabel];
  237. UILabel *numLabel = [[UILabel alloc]initWithFrame:CGRectMake((labelW+1)*i,self.itemView.height/2, labelW, 25)];
  238. numLabel.tag = i;
  239. numLabel.text = array[i];
  240. numLabel.textColor = kAppGrayColor1;
  241. numLabel.textAlignment = NSTextAlignmentCenter;
  242. numLabel.font = [UIFont systemFontOfSize:12];
  243. [self.itemView addSubview:numLabel];
  244. UIButton *itemBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  245. itemBtn.frame = CGRectMake((labelW+1)*i, 3, labelW, self.itemView.height-6);
  246. itemBtn.backgroundColor = kClearColor;
  247. itemBtn.tag = 104 + i;
  248. [itemBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  249. [self.itemView addSubview:itemBtn];
  250. if (i < array.count-1)
  251. {
  252. UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake((labelW+1)*i+labelW, 15, 1, 20)];
  253. lineView.centerY = self.itemView.height / 2;
  254. lineView.backgroundColor = kAppSpaceColor4;
  255. [self.itemView addSubview:lineView];
  256. }
  257. }
  258. }
  259. [self addSubview:self.tableView];
  260. }
  261. - (UITableView *)tableView{
  262. if (!_tableView) {
  263. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, self.height - kRealValue(45) - 10, kScreenW, kRealValue(45)) style:UITableViewStylePlain];
  264. _tableView.delegate = self;
  265. _tableView.dataSource = self;
  266. [_tableView registerNib:[UINib nibWithNibName:@"HPContributionCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"HPContributionCell"];
  267. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  268. }
  269. return _tableView;
  270. }
  271. - (void)shopBtnAction{
  272. NSLog(@"278");
  273. }
  274. -(void)clickHeadImg:(UITapGestureRecognizer *)sender{
  275. if (self.headViewBgImageBlock) {
  276. self.headViewBgImageBlock(self.clearImgView.image);
  277. }
  278. }
  279. //个人主页
  280. - (void)setViewWithModel:(UserHomeModel*)model withUserId:(NSString *)userId
  281. {
  282. //银票前三名
  283. for (UserHomeModelCuser_list *listModel in model.cuser_list) {
  284. // SenderModel *model = [SenderModel new];
  285. // model.head_image = listModel.head_image;
  286. if (listModel.is_noble_ranking_stealth == 1) {
  287. [self.imageArray addObject:@"is_noble_ranking_stealth"];
  288. }else{
  289. [self.imageArray addObject:listModel.head_image];
  290. }
  291. }
  292. [self.tableView reloadData];
  293. self.userID = userId;
  294. UserHomeModelUser *cModel;
  295. if (model.user)
  296. {
  297. cModel = model.user;
  298. }else{
  299. cModel = [[UserHomeModelUser alloc]init];
  300. }
  301. self.shopBtn.hidden = model.user.shop_status.integerValue != 1;
  302. if (model.has_focus == 1) {
  303. // [self.concertBtn setTitle:ASLocalizedString(@"已关注")forState:UIControlStateNormal];
  304. // [self.concertBtn setImage:nil forState:UIControlStateNormal];
  305. // [self.concertBtn setBackgroundImage:nil forState:UIControlStateNormal];
  306. // [self.concertBtn setBackgroundColor:[UIColor colorWithHexString:@"#E5E5E5"]];
  307. [self.concertBtn setBackgroundImage:[UIImage imageNamed:@"bogo_home_person_Concert_select"] forState:UIControlStateNormal];
  308. // self.concertBtn.layer.cornerRadius = 5;
  309. }else{
  310. // [self.concertBtn setTitle:ASLocalizedString(@"关注")forState:UIControlStateNormal];
  311. // [self.concertBtn setImage:[UIImage imageNamed:@"me_new_head_concertTitle"] forState:UIControlStateNormal];
  312. [self.concertBtn setBackgroundImage:[UIImage imageNamed:@"bogo_home_person_Concert_normal"] forState:UIControlStateNormal];
  313. // [self.concertBtn setBackgroundColor:kWhiteColor];
  314. // self.concertBtn.layer.cornerRadius = 5;
  315. }
  316. // self.outLabel.text = [NSString stringWithFormat:ASLocalizedString(@"%@的主页"),userId];
  317. self.outLabel.text = ASLocalizedString(@"用户主页");
  318. self.outLabel.hidden = YES;
  319. //底部透明图
  320. // [self.clearImgView sd_setImageWithURL:[NSURL URLWithString:cModel.head_image]];
  321. //头像
  322. [self.headImgView sd_setImageWithURL:[NSURL URLWithString:cModel.head_image] placeholderImage:kDefaultPreloadHeadImg];
  323. [self.clearImgView sd_setImageWithURL:[NSURL URLWithString:cModel.head_image] placeholderImage:kDefaultPreloadHeadImg];
  324. //认证是否显示
  325. if ([model.user.is_authentication intValue]>0)
  326. {
  327. if (model.user.v_icon && ![model.user.v_icon isEqualToString:@""])
  328. {
  329. self.certificateBtn.hidden = NO;
  330. [self.certificateBtn setTitle:model.user.v_explain forState:UIControlStateNormal];
  331. // [self.vImgView sd_setImageWithURL:[NSURL URLWithString:model.user.v_icon] placeholderImage:kDefaultPreloadHeadImg];
  332. }else
  333. {
  334. self.certificateBtn.hidden = YES;
  335. }
  336. }else
  337. {
  338. self.certificateBtn.hidden = YES;
  339. }
  340. //名字 性别 等级
  341. if (cModel.nick_name.length < 1)
  342. {
  343. cModel.nick_name = ASLocalizedString(@"暂无昵称");
  344. }
  345. // if (cModel.is_noble_ranking_stealth.intValue == 1) {
  346. // cModel.nick_name = [NSString stringWithFormat:@"神秘人%@",cModel.user_id];
  347. // }else{
  348. //
  349. // }
  350. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:cModel.nick_name];
  351. [attr setAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14.0]} range:NSMakeRange(0, cModel.nick_name.length)];
  352. CGFloat width =[cModel.nick_name sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]}].width;
  353. if (width + 52 > (kScreenW+6))
  354. {
  355. width = kScreenW-52-6;
  356. self.nameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  357. }
  358. self.nameLabel.attributedText = attr;
  359. self.nameLabel.frame = CGRectMake(0, 0, width,30);
  360. self.livingBtn.centerY = self.nameLabel.centerY;
  361. self.livingBtn.left = self.nameLabel.right + 10;
  362. self.sexImgView.frame = CGRectMake(self.nameView.left,self.nameView.bottom + 10,12,12);
  363. self.rankImgView.frame = CGRectMake(width+24,self.nameLabel.bottom,28,14);
  364. self.accountLabel.top = self.sexImgView.bottom + 5;
  365. self.itemView.top = self.accountLabel.bottom - 5;
  366. self.certificateBtn.frame = CGRectMake(self.rankImgView.right + 5, 0, kRealValue(80), 13);
  367. if (cModel.is_vip != 1) {
  368. self.vipImgView.hidden = YES;
  369. }else{
  370. self.vipImgView.hidden = NO;
  371. }
  372. if (cModel.noble_icon.length) {
  373. self.nobleImageView.hidden = NO;
  374. [self.nobleImageView sd_setImageWithURL:[NSURL URLWithString:cModel.noble_icon]];
  375. }else{
  376. self.nobleImageView.hidden = YES;
  377. }
  378. if (self.vipImgView.hidden) {
  379. // self.vipImgView.frame = CGRectMake(self.sexImgView.right + 5, self.nameLabel.bottom, 15, 15);
  380. self.rankImgView.frame = CGRectMake(self.sexImgView.right + 5, self.nameLabel.bottom, 28, 14);
  381. }else{
  382. self.vipImgView.frame = CGRectMake(self.sexImgView.right + 5, self.nameLabel.bottom, 15, 15);
  383. self.rankImgView.frame = CGRectMake(self.vipImgView.right + 5, self.nameLabel.bottom, 28, 14);
  384. }
  385. if (!self.nobleImageView.hidden) {
  386. self.nobleImageView.frame = CGRectMake(self.rankImgView.right + 5, self.nameLabel.bottom, 45, 16);
  387. self.certificateBtn.left = self.nobleImageView.right + 5;
  388. }
  389. self.nobleImageView.centerY = self.rankImgView.centerY = self.vipImgView.centerY = self.sexImgView.centerY;
  390. if ([cModel.sex isEqualToString:@"1"])
  391. {
  392. self.sexImgView.image = [UIImage imageNamed:@"com_male_selected"];
  393. }else
  394. {
  395. self.sexImgView.image = [UIImage imageNamed:@"com_female_selected"];
  396. }
  397. if (cModel.user_level.length < 1)
  398. {
  399. cModel.user_level = @"1";
  400. }
  401. self.rankImgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"level%@",cModel.user_level]];
  402. //签名
  403. if (cModel.signature.length < 1)
  404. {
  405. self.signatureLabel.text = ASLocalizedString(@"TA好像忘记签名了");
  406. }else
  407. {
  408. NSMutableAttributedString *attr1 = [[NSMutableAttributedString alloc] initWithString:cModel.signature];
  409. [attr1 setAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:12.0]} range:NSMakeRange(0,cModel.signature.length)];
  410. self.signatureLabel.attributedText = attr1;
  411. }
  412. if (cModel.luck_num.length && [cModel.luck_num intValue] > 0)
  413. {
  414. self.accountLabel.text = [NSString stringWithFormat:@"%@:%@",self.BuguLive.appModel.account_name,cModel.luck_num];
  415. }else
  416. {
  417. self.accountLabel.text = [NSString stringWithFormat:@"%@:%@",self.BuguLive.appModel.account_name,userId];
  418. }
  419. //认证
  420. NSString *v_explainString;
  421. if (cModel.v_explain.length < 1)
  422. {
  423. self.certificateView.hidden = YES;
  424. v_explainString = cModel.v_explain = ASLocalizedString(@"未认证");
  425. CGRect rect = self.certificateView.frame;
  426. rect.size.height = 0;
  427. self.certificateView.frame = rect;
  428. }else
  429. {
  430. self.certificateView.hidden = NO;
  431. self.certificateImgView.hidden = NO;
  432. v_explainString = [NSString stringWithFormat:ASLocalizedString(@"认证:%@"),cModel.v_explain];
  433. }
  434. NSMutableAttributedString *attr2 = [[NSMutableAttributedString alloc] initWithString:v_explainString];
  435. self.certificateLabel.attributedText = attr2;
  436. CGFloat width1 =[v_explainString sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}].width;
  437. self.certificateLabel.frame = CGRectMake(CGRectGetMaxX(self.certificateImgView.frame)+3, 0, width1, 21);
  438. //送出 关注 粉丝
  439. for (UILabel *label in self.itemView.subviews)
  440. {
  441. if ([label isKindOfClass:[UILabel class]])
  442. {
  443. if (label.tag == 3)
  444. {
  445. if (cModel.n_use_diamonds.length)
  446. {
  447. label.text =cModel.n_use_diamonds;
  448. }else
  449. {
  450. label.text =@"0";
  451. }
  452. }else if (label.tag == 4)
  453. {
  454. if (cModel.n_focus_count.length)
  455. {
  456. label.text =cModel.n_focus_count;
  457. }else
  458. {
  459. label.text =@"0";
  460. }
  461. }else if (label.tag == 5)
  462. {
  463. if (cModel.n_fans_count.length)
  464. {
  465. label.text =cModel.n_fans_count;
  466. }else
  467. {
  468. label.text =@"0";
  469. }
  470. }
  471. }
  472. }
  473. [self updateNewFrame];
  474. }
  475. - (void)setUIWithDict:(NSDictionary *)dict
  476. {
  477. if ([dict count])
  478. {
  479. UserModel *model2 = [UserModel mj_objectWithKeyValues:dict];
  480. if (model2.live_in == FW_LIVE_STATE_ING)
  481. {
  482. self.livingBtn.selected = YES;
  483. // [self.messageBtn setTitle:ASLocalizedString(@"直播中")forState:UIControlStateNormal];
  484. }
  485. // else if (model2.live_in == FW_LIVE_STATE_RELIVE)
  486. // {
  487. // self.livingBtn.selected = NO;
  488. //// [self.messageBtn setTitle:ASLocalizedString(@"回播中")forState:UIControlStateNormal];
  489. // }
  490. NSShadow *shadow = [[NSShadow alloc] init];
  491. shadow.shadowBlurRadius = 2;//阴影半径,默认值3
  492. shadow.shadowColor = [UIColor blackColor];//阴影颜色
  493. shadow.shadowOffset = CGSizeMake(0,2);//阴影偏移量,x向右偏移,y向下偏移,默认是(0,-3)
  494. NSAttributedString * attributedText = [[NSAttributedString alloc] initWithString:self.messageBtn.titleLabel.text attributes:@{NSShadowAttributeName:shadow}];
  495. [self.messageBtn setAttributedTitle:attributedText forState:UIControlStateNormal];
  496. }else
  497. {
  498. self.livingBtn.hidden = YES;
  499. self.messageBtn.hidden = YES;
  500. }
  501. }
  502. - (void)setCellWithModel:(userPageModel *)userInfoM
  503. {
  504. self.userID = userInfoM.user_id;
  505. //底部透明头像
  506. // [self.clearImgView sd_setImageWithURL:[NSURL URLWithString:userInfoM.head_image]];
  507. //头像
  508. [self.headImgView sd_setImageWithURL:[NSURL URLWithString:userInfoM.head_image] placeholderImage:kDefaultPreloadHeadImg];
  509. if (userInfoM.v_icon.length && [userInfoM.is_authentication intValue]== 2)
  510. {
  511. self.vImgView.hidden = NO;
  512. [self.vImgView sd_setImageWithURL:[NSURL URLWithString:userInfoM.v_icon] placeholderImage:kDefaultPreloadHeadImg];
  513. }else
  514. {
  515. self.vImgView.hidden = YES;
  516. }
  517. //账号 vip 性别 等级 编辑
  518. if (userInfoM.nick_name.length < 1)
  519. {
  520. userInfoM.nick_name = ASLocalizedString(@"暂无昵称");
  521. }
  522. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:userInfoM.nick_name];
  523. [attr setAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14.0]} range:NSMakeRange(0, userInfoM.nick_name.length)];
  524. CGFloat width =[userInfoM.nick_name sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]}].width;
  525. self.nameLabel.attributedText = attr;
  526. if ([userInfoM.sex isEqualToString:@"1"])
  527. {
  528. self.sexImgView.image = [UIImage imageNamed:@"com_male_selected"];
  529. }else
  530. {
  531. self.sexImgView.image = [UIImage imageNamed:@"com_female_selected"];
  532. }
  533. if (userInfoM.user_level.length < 1)
  534. {
  535. userInfoM.user_level = @"1";
  536. }
  537. self.rankImgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"level%@",userInfoM.user_level]];
  538. self.rankImgView.backgroundColor = kRedColor;
  539. if ([userInfoM.is_vip isEqualToString:@"1"])
  540. {
  541. if (width + 20 + 19 + 33 + 30 + 5 > kScreenW)
  542. {
  543. width = kScreenW - 20 - 19 -33 - 30;
  544. self.nameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  545. }
  546. self.nameLabel.frame = CGRectMake(0, 0, width, 30);
  547. self.sexImgView.frame = CGRectMake(10, self.nameLabel.bottom + 5, 15, 15);
  548. self.vipImgView.frame = CGRectMake(self.sexImgView.right + 5, self.nameLabel.bottom, 15, 15);
  549. self.rankImgView.frame = CGRectMake(self.vipImgView.right + 5, self.nameLabel.bottom, 28, 14);
  550. // self.editBtn.frame = CGRectMake(width+20+19+33, 0, 30,30);
  551. CGRect nameRect = self.nameView.frame;
  552. nameRect.size.width = (width+20+19+33+30);
  553. nameRect.origin.x = (kScreenW - (width+20+19+33+30))/2;
  554. self.nameView.frame = nameRect;
  555. }else
  556. {
  557. if (width +19 +33 +30 > (kScreenW+6))
  558. {
  559. width = kScreenW-19 -33 -30-6;
  560. self.nameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  561. }
  562. self.nameLabel.frame = CGRectMake(0, 0, width, 30);
  563. self.sexImgView.frame = CGRectMake(0, self.nameLabel.bottom + 5, 15, 15);
  564. // self.vipImgView.frame = CGRectMake(self.sexImgView.right + 5, self.nameLabel.bottom, 15, 15);
  565. self.rankImgView.frame = CGRectMake(self.sexImgView.right + 5, self.nameLabel.bottom, 28, 14);
  566. CGRect nameRect = self.nameView.frame;
  567. nameRect.size.width = (width +19 +33 +30);
  568. nameRect.origin.x = (kScreenW - (width +19 +33 +30))/2;
  569. self.nameView.frame = nameRect;
  570. }
  571. self.certificateView.centerY = self.rankImgView.centerY;
  572. if (self.nobleImageView.hidden) {
  573. self.certificateBtn.left = self.rankImgView.right;
  574. }else{
  575. self.certificateBtn.left = self.nobleImageView.right;
  576. }
  577. //签名
  578. if (userInfoM.signature.length < 1)
  579. {
  580. self.signatureLabel.text = ASLocalizedString(@"TA好像忘记签名了");
  581. }else
  582. {
  583. NSMutableAttributedString *attr1 = [[NSMutableAttributedString alloc] initWithString:userInfoM.signature];
  584. [attr1 setAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:12.0]} range:NSMakeRange(0,userInfoM.signature.length)];
  585. self.signatureLabel.attributedText = attr1;
  586. }
  587. //账号
  588. if ([userInfoM.luck_num intValue] > 0)
  589. {
  590. if (self.BuguLive.appModel.account_name.length > 0)
  591. {
  592. self.accountLabel.text =[NSString stringWithFormat:@"%@:%@",self.BuguLive.appModel.account_name, userInfoM.luck_num];
  593. }else
  594. {
  595. self.accountLabel.text =[NSString stringWithFormat:@"%@:%@",self.BuguLive.appModel.account_name,userInfoM.luck_num];
  596. }
  597. }
  598. else
  599. {
  600. if (self.BuguLive.appModel.account_name.length > 0)
  601. {
  602. self.accountLabel.text =[NSString stringWithFormat:@"%@:%@",self.BuguLive.appModel.account_name, userInfoM.user_id];
  603. }else
  604. {
  605. self.accountLabel.text =[NSString stringWithFormat:@"%@:%@",
  606. ASLocalizedString(@"账号"), userInfoM.user_id];
  607. }
  608. }
  609. //认证
  610. NSString *v_explainString;
  611. if (userInfoM.v_explain.length < 1)
  612. {
  613. self.certificateView.hidden = YES;
  614. v_explainString = userInfoM.v_explain = ASLocalizedString(@"未认证");
  615. CGRect rect = self.certificateView.frame;
  616. rect.size.height = 0;
  617. self.certificateView.frame = rect;
  618. }else
  619. {
  620. self.certificateView.hidden = NO;
  621. self.certificateImgView.hidden = NO;
  622. v_explainString = [NSString stringWithFormat:ASLocalizedString(@"认证:%@"),userInfoM.v_explain];
  623. NSMutableAttributedString *attr2 = [[NSMutableAttributedString alloc] initWithString:v_explainString];
  624. self.certificateLabel.attributedText = attr2;
  625. CGFloat width1 =[v_explainString sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}].width;
  626. self.certificateLabel.frame = CGRectMake(CGRectGetMaxX(self.certificateImgView.frame)+3, 0, width1, 21);
  627. CGRect rect = self.certificateView.frame;
  628. rect.size.width = width1+20;
  629. rect.size.height = 21;
  630. self.certificateView.frame = rect;
  631. self.certificateLabel.frame = CGRectMake(18, 0, width1, 21);
  632. }
  633. //直播 小视频 关注 粉丝
  634. for (UILabel *label in self.itemView.subviews)
  635. {
  636. if ([label isKindOfClass:[UILabel class]])
  637. {
  638. if (label.tag == 4)
  639. {
  640. if (userInfoM.n_video_count.length)
  641. {
  642. label.text = userInfoM.n_video_count;
  643. }else
  644. {
  645. label.text =@"0";
  646. }
  647. }else if (label.tag == 5)
  648. {
  649. if (userInfoM.n_svideo_count.length)
  650. {
  651. label.text =userInfoM.n_svideo_count;
  652. }else
  653. {
  654. label.text =@"0";
  655. }
  656. }else if (label.tag == 6)
  657. {
  658. if (userInfoM.n_focus_count.length)
  659. {
  660. label.text =userInfoM.n_focus_count;
  661. }else
  662. {
  663. label.text =@"0";
  664. }
  665. }else if (label.tag == 7)
  666. {
  667. if (userInfoM.n_fans_count.length)
  668. {
  669. label.text =userInfoM.n_fans_count;
  670. }else
  671. {
  672. label.text =@"0";
  673. }
  674. }
  675. }
  676. }
  677. [self updateNewFrame];
  678. }
  679. - (void)updateNewFrame
  680. {
  681. //透明图片和透明view
  682. // CGRect newRect = self.clearView.frame =self.clearImgView.frame;
  683. // newRect.size.height = CGRectGetMaxY(self.certificateView.frame) +40;
  684. self.clearView.frame = CGRectMake(10, 223, kScreenW - 10 * 2, kRealValue(164));
  685. self.shopBtn.top = self.clearView.top - 30;
  686. if (!self.nobleImageView.hidden) {
  687. self.certificateBtn.frame = CGRectMake(self.nobleImageView.right + 3, 0, 200, 20);
  688. }else{
  689. self.certificateBtn.frame = CGRectMake(self.rankImgView.right + 3, 0, 200, 20);
  690. }
  691. self.certificateBtn.centerY = self.rankImgView.centerY;
  692. //self.certificateBtn.left = self.rankImgView.right + 2;
  693. self.headImgView.hidden = YES;
  694. // //底部灰色view
  695. // CGRect bottomRect = self.bottomView.frame;
  696. // bottomRect.origin.y = CGRectGetMaxY(self.clearView.frame);
  697. // self.bottomView.frame = bottomRect;
  698. // //底部灰色view
  699. // CGRect itemRect = self.itemView.frame;
  700. // itemRect.origin.y = CGRectGetMaxY(self.clearView.frame)-20;
  701. // self.itemView.frame = itemRect;
  702. // //本身的view
  703. // CGRect myRect = self.frame;
  704. // myRect.size.height = self.clearView.size.height+60;
  705. // self.frame = myRect;
  706. }
  707. -(void)clickAttention:(UIButton *)sender{
  708. NSMutableDictionary *dictM = [[NSMutableDictionary alloc]init];
  709. [dictM setObject:@"user" forKey:@"ctl"];
  710. [dictM setObject:@"follow" forKey:@"act"];
  711. [dictM setObject:self.userID forKey:@"to_user_id"];
  712. FWWeakify(self)
  713. [[NetHttpsManager manager] POSTWithParameters:dictM SuccessBlock:^(NSDictionary *responseJson)
  714. {
  715. if ([responseJson toInt:@"status"] == 1)
  716. {
  717. NSInteger has_focus = [responseJson toInt:@"has_focus"];
  718. if (has_focus == 1) {
  719. // [sender setTitle:ASLocalizedString(@"已关注")forState:UIControlStateNormal];
  720. // [sender setImage:nil forState:UIControlStateNormal];
  721. [sender setBackgroundImage:[UIImage imageNamed:@"bogo_home_person_Concert_select"] forState:UIControlStateNormal];
  722. // [sender setBackgroundColor:[UIColor colorWithHexString:@"#E5E5E5"]];
  723. // sender.layer.cornerRadius = 5;
  724. if (self.headViewAttentionBlock) {
  725. self.headViewAttentionBlock(YES);
  726. }
  727. }else{
  728. // [sender setTitle:ASLocalizedString(@"关注")forState:UIControlStateNormal];
  729. // [sender setImage:[UIImage imageNamed:@"me_new_head_concertTitle"] forState:UIControlStateNormal];
  730. [sender setBackgroundImage:[UIImage imageNamed:@"bogo_home_person_Concert_normal"] forState:UIControlStateNormal];
  731. // [sender setBackgroundColor:kWhiteColor];
  732. // sender.layer.cornerRadius = 5;
  733. if (self.headViewAttentionBlock) {
  734. self.headViewAttentionBlock(NO);
  735. }
  736. }
  737. }
  738. } FailureBlock:^(NSError *error)
  739. {
  740. NSLog(@"error===%@",error);
  741. }];
  742. }
  743. - (void)buttonClick:(UIButton *)btn
  744. {
  745. if (self.headViewBlock)
  746. {
  747. self.headViewBlock((int)btn.tag);
  748. }
  749. }
  750. /**
  751. 设置 角标
  752. @param sender 对应的控件
  753. */
  754. - (void)initBadgeBtn:(UIButton *)sender
  755. {
  756. //-好友
  757. _badge = [[JSBadgeView alloc]initWithParentView:sender alignment:JSBadgeViewAlignmentTopRight];
  758. _badge.badgePositionAdjustment = CGPointMake(-6, 3);
  759. }
  760. #pragma mark - UITableViewDelegate,UITableViewDataSource
  761. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  762. return 1;
  763. }
  764. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  765. return 1;
  766. }
  767. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  768. HPContributionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HPContributionCell" forIndexPath:indexPath];
  769. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  770. [cell setCellWithArray:self.imageArray];
  771. return cell;
  772. }
  773. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  774. return kRealValue(45);
  775. }
  776. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  777. if (self.delegate && [self.delegate respondsToSelector:@selector(headView:didClickContribution:)]) {
  778. [self.delegate headView:self didClickContribution:nil];
  779. }
  780. }
  781. - (NSMutableArray *)imageArray
  782. {
  783. if (!_imageArray)
  784. {
  785. _imageArray = [[NSMutableArray alloc]init];
  786. }
  787. return _imageArray;
  788. }
  789. @end