CommonSexView.m 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // CommonSexView.m
  3. // UniversalApp
  4. //
  5. // Created by bogokj on 2019/11/6.
  6. // Copyright © 2019 voidcat. All rights reserved.
  7. //
  8. #import "CommonSexView.h"
  9. @interface CommonSexView ()
  10. @property (strong, nonatomic) UIImageView *sexImageView;
  11. @property (strong, nonatomic) UILabel *ageLabel;
  12. @end
  13. @implementation CommonSexView
  14. - (instancetype)initWithFrame:(CGRect)frame{
  15. if (self = [super initWithFrame:frame]) {
  16. }
  17. return self;
  18. }
  19. - (void)setSex:(BogoSex)sex age:(NSInteger)age{
  20. if (![self.subviews containsObject:self.sexImageView]) {
  21. [self addSubview:self.sexImageView];
  22. }
  23. if (![self.subviews containsObject:self.ageLabel]) {
  24. [self addSubview:self.ageLabel];
  25. }
  26. [self.sexImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  27. make.edges.equalTo(self);
  28. }];
  29. [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.right.equalTo(self).offset(-2.5);
  31. make.top.bottom.equalTo(self);
  32. }];
  33. self.sexImageView.image = [UIImage imageNamed:sex == BogoMale ? @"boy_icon" : @"girl_icon"];
  34. // if (age) {
  35. // [self.ageLabel setText:[NSString stringWithFormat:@"%ld",age]];
  36. // self.ageLabel.font = [UIFont systemFontOfSize:10];
  37. // }else{
  38. // [self.ageLabel setText:ASLocalizedString(@"保密")];
  39. // self.ageLabel.font = [UIFont systemFontOfSize:7];
  40. // }
  41. }
  42. - (UIImageView *)sexImageView{
  43. if (!_sexImageView) {
  44. _sexImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
  45. _sexImageView.contentMode = UIViewContentModeScaleToFill;
  46. }
  47. return _sexImageView;
  48. }
  49. - (UILabel *)ageLabel{
  50. if (!_ageLabel) {
  51. _ageLabel = [[UILabel alloc]initWithFrame:CGRectZero];
  52. // _ageLabel.textColor = kWhiteColor;
  53. _ageLabel.font = [UIFont systemFontOfSize:10];
  54. _ageLabel.textAlignment = NSTextAlignmentRight;
  55. }
  56. return _ageLabel;
  57. }
  58. @end