Latest 1.0.6
Homepage https://github.com/songyutao/YTSegmentedControl
License MIT
Platforms ios 7.0, requires ARC
Authors

a custom sliding segmented control

Examples:

UIAppearance setting

UIImage *selectedImage = [[UIImage imageNamed:@"segmented_selected"] stretchableImageWithLeftCapWidth:[UIImage imageNamed:@"segmented_selected"].size.width/2 topCapHeight:[UIImage imageNamed:@"segmented_selected"].size.height/2];
UIImage *unSelectedImage = [[UIImage imageNamed:@"segmented_bg"] stretchableImageWithLeftCapWidth:[UIImage imageNamed:@"segmented_bg"].size.width/2 topCapHeight:[UIImage imageNamed:@"segmented_bg"].size.height/2];
[[YTSegmentedControl appearance] setSelectedItemBgImage:selectedImage];
[[YTSegmentedControl appearance] setNormalItemBgImage:unSelectedImage];
[[YTSegmentedControl appearance] setNormalAttributeDictionary:@{NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:[UIColor blueColor]}];
[[YTSegmentedControl appearance] setSelectedAttributeDictionary:@{NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:[UIColor grayColor]}];
[[YTSegmentedControl appearance] setContentEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 10)];
[[YTSegmentedControl appearance] setItemWidth:80];

Use way:

YTSegmentedItem *item = [[YTSegmentedItem alloc] initWithTitle:@"zero" image:nil];
YTSegmentedItem *item2 = [[YTSegmentedItem alloc] initWithTitle:@"one" image:nil];
YTSegmentedItem *item3 = [[YTSegmentedItem alloc] initWithTitle:@"two" image:nil];
YTSegmentedItem *item4 = [[YTSegmentedItem alloc] initWithTitle:@"three" image:nil];

YTSegmentedControl *segmentedControl = [[YTSegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:item, item2, item3, item4, nil]];
segmentedControl.frame = CGRectMake(10, 40, 200, 50);
[segmentedControl addTarget:self action:@selector(segmentedControlSelected:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:segmentedControl];

Latest podspec

{
    "name": "YTSegmentedControl",
    "platforms": {
        "ios": "7.0"
    },
    "version": "1.0.6",
    "license": "MIT",
    "summary": "a custom sliding segmented control",
    "homepage": "https://github.com/songyutao/YTSegmentedControl",
    "authors": {
        "u5b8bu7389u6d9b": "[email protected]"
    },
    "source": {
        "git": "https://github.com/songyutao/YTSegmentedControl.git",
        "tag": "1.0.6"
    },
    "requires_arc": true,
    "subspecs": [
        {
            "name": "YTSegmentedControl",
            "source_files": "YTSegmentedControl/YTSegmentedControl",
            "frameworks": [
                "UIKit"
            ]
        }
    ]
}

Pin It on Pinterest

Share This