pmick / NXTSegmentedControl

The styled swipe-able segmented control used in Next
MIT License
98 stars 8 forks source link

border #8

Closed lyuxxx closed 5 years ago

lyuxxx commented 7 years ago
2016-12-15 2 59 18

Maybe you can add a border feature like this,I do it by modify your source code. Another,I show it on a UITableViewCell,the thumb will flash to show when the cell will display.I don't know the reason,hope you can help.(my poor English...)

pmick commented 7 years ago

Adding the ability to add a border seems like a pretty good idea. I will take a look at throwing some of these into table cells and see if I can reproduce your bug. @KaWaDaTa if you can post any code that lets me reproduce that would be great.

lyuxxx commented 7 years ago
NXTSegmentedControl *switch1 = [[NXTSegmentedControl alloc] initWithItems:@[@"ON",@"OFF"]];
        [self.controls addObject:switch1];
        switch1.tintColor = [UIColor whiteColor];
        if (model.homeComponentModels[0].on == YES) {
            switch1.selectedSegmentIndex = 0;
        } else if (model.homeComponentModels[0].on == NO) {
            switch1.selectedSegmentIndex = 1;
        }
        [switch1 setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor colorWithHexString:@"#cacaca"] forKey:NSForegroundColorAttributeName] forState:UIControlStateNormal];
        switch1.thumbColor = [UIColor colorWithHexString:@"#008ea2"];
        [self addSubview:switch1];//"self" is a view contained by cell.contentView
        [switch1 makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@40);
            make.right.equalTo(@(-40));
            make.width.equalTo(@110);
            make.height.equalTo(@50);
        }];
Sebacho-Barajas commented 7 years ago

Any update on this enhancement ?

pmick commented 7 years ago

Hey, I haven't gotten a chance to add a border. Go ahead and open a PR if you two need that feature.

I put a bunch of these into a table view with code similar to yours, and still couldn't reproduce what you're seeing.

Sebacho-Barajas commented 7 years ago

I added a border by doing this.

 CGFloat viewWidth = CGRectGetWidth(self.view.frame);

    _segmentedControl = [[NXTSegmentedControl alloc] initWithItems:@[@"Test 1",@"Test 2"]];
    _segmentedControl.selectedSegmentIndex = 1;
    _segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
    //  _segmentedControl.frame = CGRectMake(0, 63, viewWidth, 44);
    _segmentedControl.frame = CGRectMake(0, 0, viewWidth, 44);
    _segmentedControl.tintColor = [UIColor clearColor];
    //_segmentedControl.tintColor = self.collectionView.backgroundColor;

    [_segmentedControl addTarget:self
                          action:@selector(segmentedControlChangedValue:)
                forControlEvents:UIControlEventValueChanged];

    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    effectView.frame = CGRectMake(0, 170, viewWidth, 44);
    effectView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;

    effectView.layer.cornerRadius = 44 / 2.0f;
    effectView.layer.borderWidth = 1.0f;
    effectView.layer.borderColor = [UIColor whiteColor].CGColor;

    [effectView addSubview:_segmentedControl];

    [self.view addSubview:effectView];