YMBaseCustomNavView.m 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // YMBaseCustomNavView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2023/11/7.
  6. //
  7. #import "YMBaseCustomNavView.h"
  8. @interface YMBaseCustomNavView ()
  9. @property (nonatomic, strong, readwrite) UIView *ym_customNavBarLine;
  10. @end
  11. @implementation YMBaseCustomNavView
  12. - (instancetype)initWithFrame:(CGRect)frame{
  13. if (self = [super initWithFrame:frame]) {
  14. [self addSubview:self.ym_customBackgroundImage];
  15. [self.ym_customBackgroundImage addSubview:self.ym_customNavBar];
  16. [self addSubview:self.ym_customNavBarLine];
  17. }
  18. return self;
  19. }
  20. - (void)updateConstraints{
  21. [self.ym_customNavBar mas_makeConstraints:^(MASConstraintMaker *make) {
  22. make.top.equalTo(self.ym_customBackgroundImage).offset(kYMNavHeight - 44);
  23. make.left.equalTo(self.ym_customBackgroundImage);
  24. make.right.equalTo(self.ym_customBackgroundImage);
  25. make.height.mas_equalTo(44);
  26. }];
  27. [self.ym_customBackgroundImage mas_makeConstraints:^(MASConstraintMaker *make) {
  28. make.top.equalTo(self);
  29. make.left.equalTo(self);
  30. make.right.equalTo(self);
  31. make.bottom.equalTo(self);
  32. }];
  33. [self.ym_customNavBarLine mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.bottom.equalTo(self);
  35. make.left.equalTo(self);
  36. make.right.equalTo(self);
  37. make.height.mas_equalTo(0.5);
  38. }];
  39. [super updateConstraints];
  40. }
  41. - (UIImageView *)ym_customBackgroundImage{
  42. if (!_ym_customBackgroundImage) {
  43. _ym_customBackgroundImage = [[UIImageView alloc]init];
  44. _ym_customBackgroundImage.contentMode = UIViewContentModeScaleAspectFill;
  45. _ym_customBackgroundImage.userInteractionEnabled = YES;
  46. }
  47. return _ym_customBackgroundImage;
  48. }
  49. - (UINavigationItem *)ym_customNavItem {
  50. if (!_ym_customNavItem) {
  51. _ym_customNavItem = [[UINavigationItem alloc]init];
  52. }
  53. return _ym_customNavItem;
  54. }
  55. - (UINavigationBar *)ym_customNavBar {
  56. if (!_ym_customNavBar) {
  57. _ym_customNavBar = [[UINavigationBar alloc]init];
  58. [_ym_customNavBar pushNavigationItem:self.ym_customNavItem animated:NO];
  59. _ym_customNavBar.barTintColor = UIColor.clearColor;
  60. [_ym_customNavBar setBackgroundImage:[[UIImage alloc] init]
  61. forBarPosition:UIBarPositionAny
  62. barMetrics:UIBarMetricsDefault];
  63. _ym_customNavBar.shadowImage = [[UIImage alloc] init];
  64. _ym_customNavBar.translucent = NO;
  65. _ym_customNavBar.barStyle = UIBarStyleDefault;
  66. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
  67. paragraphStyle.alignment = NSTextAlignmentCenter;
  68. paragraphStyle.lineSpacing = 1;
  69. NSDictionary *attributes= @{
  70. NSForegroundColorAttributeName:UIColor.blackColor,
  71. NSParagraphStyleAttributeName:paragraphStyle
  72. };
  73. [_ym_customNavBar setTitleTextAttributes:attributes];
  74. }
  75. return _ym_customNavBar;
  76. }
  77. - (UIView *)ym_customNavBarLine {
  78. if (!_ym_customNavBarLine) {
  79. _ym_customNavBarLine = [[UIView alloc]init];
  80. _ym_customNavBarLine.backgroundColor = HexColorFromRGB(0xe0e0e0);
  81. _ym_customNavBarLine.hidden = YES;
  82. }
  83. return _ym_customNavBarLine;
  84. }
  85. @end