| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- //
- // HJMeDistributeView.m
- // HappyJob
- //
- // Created by Bob on 2019/4/18.
- // Copyright © 2019 Bob. All rights reserved.
- //
- #import "HJMeDistributeView.h"
- #import "UIButton+Layout.h"
- @interface HJMeDistributeView ()
- @end
- @implementation HJMeDistributeView
- - (instancetype)init {
-
- if (self = [super init])
- {
- [self addSubview:self.favoriteButton];
- [self addSubview:self.applyButton];
- [self addSubview:self.invitationButton];
-
- [self makeConstraints];
- }
- return self;
- }
- #pragma mark - life cycle
- - (void)makeConstraints {
- // 三等分布局
- CGSize buttonSize = self.favoriteButton.frame.size;
- NSArray *views = @[self.favoriteButton, self.applyButton, self.invitationButton];
- CGFloat leadSpacing = 40;
- CGFloat tailSpacing = 40;
- CGFloat fixedSpacing = (SCREEN_WIDTH - buttonSize.width * views.count - leadSpacing - tailSpacing) / (views.count - 1);
- [views mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:fixedSpacing leadSpacing:leadSpacing tailSpacing:tailSpacing];
- [views mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).with.offset(0);
- make.height.mas_equalTo(buttonSize.height);
- }];
- [self mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(self.applyButton.mas_bottom).with.offset(20);
- }];
- }
- #pragma mark - private methods
- - (UIButton *)createButtonWithTitle:(NSString *)title imageNamed:(NSString *)imageNamed {
-
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- button.titleLabel.font = [UIFont systemFontOfSize:12];
- button.titleLabel.textAlignment = NSTextAlignmentCenter;
- [button setImage:[UIImage imageNamed:imageNamed] forState:UIControlStateNormal];
- [button setTitle:title forState:UIControlStateNormal];
- [button setTitleColor:COLOR_BACK6 forState:UIControlStateNormal];
- //文字图片上下显示
- CGSize imageSize = CGSizeMake(HJHorizontalScale(34), HJHorizontalScale(34));
- CGSize titleSize = CGSizeMake(HJHorizontalScale(60), HJHorizontalScale(13));
- CGFloat maxWidth = MAX(imageSize.width, titleSize.width);
- CGFloat padding = 10;
- button.imageRect = CGRectMake((maxWidth - imageSize.width) / 2, 0, imageSize.width, imageSize.height);
- button.titleRect = CGRectMake((maxWidth - titleSize.width) / 2, imageSize.height + padding, titleSize.width, titleSize.height);
- button.frame = CGRectMake(0, 0, maxWidth, imageSize.height + titleSize.height + padding);
-
- return button;
- }
- #pragma mark - getters and setters
- - (UIButton *)favoriteButton {
-
- if (_favoriteButton == nil)
- {
- _favoriteButton = [self createButtonWithTitle:@"我的收藏" imageNamed:@"me_favorite"];
- }
- return _favoriteButton;
- }
- - (UIButton *)applyButton {
-
- if (_applyButton == nil)
- {
- _applyButton = [self createButtonWithTitle:@"我的投递" imageNamed:@"me_apply"];
- }
- return _applyButton;
- }
- - (UIButton *)invitationButton {
-
- if (_invitationButton == nil)
- {
- _invitationButton = [self createButtonWithTitle:@"面试邀请" imageNamed:@"me_invitation"];
- }
- return _invitationButton;
- }
- @end
|