1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- //
- // YMBaseCustomNavView.m
- // MSYOUPAI
- //
- // Created by YoMi on 2023/11/7.
- //
- #import "YMBaseCustomNavView.h"
- @interface YMBaseCustomNavView ()
- @property (nonatomic, strong, readwrite) UIView *ym_customNavBarLine;
- @end
- @implementation YMBaseCustomNavView
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
- [self addSubview:self.ym_customBackgroundImage];
- [self.ym_customBackgroundImage addSubview:self.ym_customNavBar];
- [self addSubview:self.ym_customNavBarLine];
- }
- return self;
- }
- - (void)updateConstraints{
- [self.ym_customNavBar mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.ym_customBackgroundImage).offset(kYMNavHeight - 44);
- make.left.equalTo(self.ym_customBackgroundImage);
- make.right.equalTo(self.ym_customBackgroundImage);
- make.height.mas_equalTo(44);
- }];
-
- [self.ym_customBackgroundImage mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self);
- make.left.equalTo(self);
- make.right.equalTo(self);
- make.bottom.equalTo(self);
- }];
-
- [self.ym_customNavBarLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(self);
- make.left.equalTo(self);
- make.right.equalTo(self);
- make.height.mas_equalTo(0.5);
- }];
-
- [super updateConstraints];
- }
- - (UIImageView *)ym_customBackgroundImage{
- if (!_ym_customBackgroundImage) {
- _ym_customBackgroundImage = [[UIImageView alloc]init];
- _ym_customBackgroundImage.contentMode = UIViewContentModeScaleAspectFill;
- _ym_customBackgroundImage.userInteractionEnabled = YES;
- }
- return _ym_customBackgroundImage;
- }
- - (UINavigationItem *)ym_customNavItem {
- if (!_ym_customNavItem) {
- _ym_customNavItem = [[UINavigationItem alloc]init];
- }
- return _ym_customNavItem;
- }
- - (UINavigationBar *)ym_customNavBar {
- if (!_ym_customNavBar) {
- _ym_customNavBar = [[UINavigationBar alloc]init];
- [_ym_customNavBar pushNavigationItem:self.ym_customNavItem animated:NO];
- _ym_customNavBar.barTintColor = UIColor.clearColor;
- [_ym_customNavBar setBackgroundImage:[[UIImage alloc] init]
- forBarPosition:UIBarPositionAny
- barMetrics:UIBarMetricsDefault];
- _ym_customNavBar.shadowImage = [[UIImage alloc] init];
- _ym_customNavBar.translucent = NO;
- _ym_customNavBar.barStyle = UIBarStyleDefault;
- NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
- paragraphStyle.alignment = NSTextAlignmentCenter;
- paragraphStyle.lineSpacing = 1;
- NSDictionary *attributes= @{
- NSForegroundColorAttributeName:UIColor.blackColor,
- NSParagraphStyleAttributeName:paragraphStyle
- };
- [_ym_customNavBar setTitleTextAttributes:attributes];
- }
- return _ym_customNavBar;
- }
- - (UIView *)ym_customNavBarLine {
- if (!_ym_customNavBarLine) {
- _ym_customNavBarLine = [[UIView alloc]init];
- _ym_customNavBarLine.backgroundColor = HexColorFromRGB(0xe0e0e0);
- _ym_customNavBarLine.hidden = YES;
- }
- return _ym_customNavBarLine;
- }
- @end
|