• UISegmentedControl 踩坑


    @interface JLMyContactsViewController ()

    @property (nonatomic, strong)   UIImageView *navImageView;

    @property (nonatomic, strong)   UISegmentedControl *titleV;

    @property (nonatomic, strong)   NSMutableArray *titleVImages;

    @property (nonatomic, strong)   NSArray *titleVImageNames;

    @end

     

    - (void)setUpUI{

        

        self.titleVImageNames = @[@"我的人脉点击11_03",@"我的人脉未点击11_03",@"时间轴点击_03",@"时间轴未点击_03"];

        

    //    self.titleVImages = [NSMutableArray array];

        

        [self.titleVImageNames enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {

            //

            UIImage *image = [[UIImage imageNamed:(NSString *)obj] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

            UIImage *newImage = [[UIImage scaleToSize:image size:CGSizeMake( JLAppWidth/9*5/2, JLAppHeight/20 - 10)] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

            [self.titleVImages addObject:newImage];

        }];

        

        

        [self.titleV setImage:self.titleVImages[0] forSegmentAtIndex:0];

        [self.titleV setImage:self.titleVImages[3] forSegmentAtIndex:1];

        

        self.titleV.selectedSegmentIndex = 0;

        

        [self.titleV addTarget:self action:@selector(titleVChange:) forControlEvents:UIControlEventValueChanged];

        

        [self.view addSubview:self.titleV];

        

    }

    #pragma mark --PrivateMethod

    - (void)titleVChange:(UISegmentedControl *)sender{

            sender.selected = !sender.selected;

        

        [self.titleV setImage:sender.selected ?self.titleVImages[1]:self.titleVImages[0] forSegmentAtIndex:0];

        [self.titleV setImage:sender.selected ? self.titleVImages[2]:self.titleVImages[3] forSegmentAtIndex:1];

     

        if (sender.selectedSegmentIndex == 0) {

            

            //1.添加tableView 2.移除时间轴

     

        }else{

            //相反

     

        }

    }

     

     

    #pragma mark --Getter

    -(UIImageView *)navImageView{

        if (!_navImageView) {

            _navImageView = [[UIImageView alloc] init];

            _navImageView.frame = CGRectMake(0, 0, JLAppWidth/5 + 10, 25);

        }

        return _navImageView;

    }

     

    - (UISegmentedControl *)titleV{

        if (!_titleV) {

            _titleV = [[UISegmentedControl alloc] initWithItems:@[self.titleVImages[0] ,self.titleVImages[3]]];

            _titleV.frame = CGRectMake(JLAppWidth/8 *3 - 60, 10, JLAppWidth/9*5, JLAppHeight/20 - 10);

            _titleV.tintColor = [UIColor colorWithRed:0.8196 green:0.8196 blue:0.8196 alpha:1.0];

        }

        return _titleV;

    }

  • 相关阅读:
    android中kl布局文件加载失败解决办法
    android系统输入按键流程
    linux键值转android键值配置文件
    linux键值到Android键值的转换与自定义
    linux中ioctl的应用与说明
    zabbix邮件告警
    linux 双网关双IP设置
    随笔
    记录一次事故
    python解析.yml/.yaml文件--pyyaml模块(第三方)
  • 原文地址:https://www.cnblogs.com/Jenaral/p/5160267.html
Copyright © 2020-2023  润新知