123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- //
- // SPSBChooseCityNavigationView.m
- // 我的社保
- //
- // Created by shanp on 2021/5/20.
- //
- #import "SPSBChooseCityNavigationView.h"
- #import "SPSBUIGeneralHeader.h"
- #define spsb_chooseCityNavigationHeight ((jxh_screenHeight() - 180) > 400 ? 400 : (jxh_screenHeight() - 180))
- #define spsb_chooseCityNavigationViewLabelTag 3000
- #define spsb_chooseCityNavigationLabelTag 10000
- @interface SPSBChooseCityNavigationView () {
- NSInteger _count;
- CGFloat _navigationHeight;
- }
- @end
- @implementation SPSBChooseCityNavigationView
- - (instancetype)initWithArray:(NSArray *)array {
- self = [super init];
- if (!self) return nil;
- _count = array.count;
- _navigationHeight = 15 * _count;
- _navigationHeight = _navigationHeight < (jxh_screenHeight() - 180) ? _navigationHeight : jxh_screenHeight() - 180;
- self.backgroundColor = [UIColor whiteColor];
- UILabel *tempLabel = nil;
- for (NSInteger i = 0; i < _count; i ++) {
- UILabel *label = [UILabel convenienceWithFont:spsb_semiboldFont(11) text:[array objectAtIndex:i] textColor:spsb_3296FB_color() textAlignment:NSTextAlignmentCenter];
- label.tag = spsb_chooseCityNavigationViewLabelTag + i;
- [self addSubview:label];
- [label makeConstraints:^(JXHConstraintMaker *make) {
- if (tempLabel) {
- make.top.equalTo(tempLabel.bottom);
- } else {
- make.top.equalTo((jxh_screenHeight() - self->_navigationHeight - 64) / 2);
- }
- make.leading.equalTo(0);
- make.trailing.equalTo(0);
- make.height.equalTo(self->_navigationHeight / self->_count);
- }];
- tempLabel = label;
- }
- return self;
- }
- - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
- UITouch *touch = [touches anyObject];
- CGPoint touchPoint = [touch locationInView:self];
- if (touchPoint.y > (jxh_screenHeight() - _navigationHeight - 64) / 2
- && touchPoint.y < (jxh_screenHeight() - _navigationHeight - 64) / 2 + _navigationHeight) {
- NSInteger temp = (touchPoint.y - (jxh_screenHeight() - _navigationHeight - 64) / 2) / (_navigationHeight / _count);
- if (temp > _count - 1) {
- self.spsb_section = _count - 1;
- } else {
- self.spsb_section = temp;
- }
- [self addNavigationLabel];
- }
- }
- - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
- UITouch *touch = [touches anyObject];
- CGPoint touchPoint = [touch locationInView:self];
- if (touchPoint.y <= (jxh_screenHeight() - _navigationHeight - 64) / 2) {
- self.spsb_section = 0;
- } else if (touchPoint.y >= (jxh_screenHeight() - _navigationHeight - 64) / 2 + _navigationHeight) {
- self.spsb_section = _count - 1;
- } else {
- NSInteger temp = (touchPoint.y - (jxh_screenHeight() - _navigationHeight - 64) / 2) / (_navigationHeight / _count);
- if (temp > _count - 1) {
- self.spsb_section = _count - 1;
- } else {
- self.spsb_section = temp;
- }
- }
- UILabel *navigationLabel = (UILabel *)[self viewWithTag:spsb_chooseCityNavigationLabelTag];
- if (navigationLabel) {
- navigationLabel.text = ((UILabel *)[self viewWithTag:spsb_chooseCityNavigationViewLabelTag + self.spsb_section]).text;
- } else {
- [self addNavigationLabel];
- }
- }
- - (void)touchesEnded:(NSSet *)touches
- withEvent:(UIEvent *)event {
- UILabel *navigationLabel = (UILabel *)[self viewWithTag:spsb_chooseCityNavigationLabelTag];
- [navigationLabel removeFromSuperview];
- }
- //添加导航标示
- - (void)addNavigationLabel {
- UILabel *navigationLabel = [UILabel convenienceWithFont:spsb_font(30) text:((UILabel *)[self viewWithTag:spsb_chooseCityNavigationViewLabelTag + self.spsb_section]).text textColor:spsb_FFFFFF_color(1.f) textAlignment:NSTextAlignmentCenter];
- navigationLabel.tag = spsb_chooseCityNavigationLabelTag;
- [navigationLabel setLayerCornerRadius:5 clipToBounds:true];
-
- navigationLabel.backgroundColor = spsb_000000_color(0.8);
- [self addSubview:navigationLabel];
-
- [navigationLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.centerX.equalTo(navigationLabel.superview.superview.centerX);
- make.centerY.equalTo(navigationLabel.superview.superview.centerY).offset(-64 / 2);
- make.size.equalTo(CGSizeMake(80, 80));
- }];
- }
- @end
- #undef spsb_chooseCityNavigationHeight
- #undef spsb_chooseCityNavigationViewLabelTag
- #undef spsb_chooseCityNavigationLabelTag
|