├── .gitignore ├── Class ├── TLSegmentedControl.h └── TLSegmentedControl.m ├── LICENSE ├── README.md ├── ScreenShot └── 1.gif ├── TLSegmentedControl.podspec ├── TLSegmentedControl.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata └── TLSegmentedControl ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj └── LaunchScreen.storyboard ├── Info.plist ├── ViewController.h ├── ViewController.m └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata 19 | 20 | ## Other 21 | *.xccheckout 22 | *.moved-aside 23 | *.xcuserstate 24 | *.xcscmblueprint 25 | 26 | ## Obj-C/Swift specific 27 | *.hmap 28 | *.ipa 29 | Pods/ 30 | Podfile.lock 31 | 32 | 33 | # Swift Package Manager 34 | # 35 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 36 | # Packages/ 37 | .build/ 38 | 39 | # CocoaPods 40 | # 41 | # We recommend against adding the Pods directory to your .gitignore. However 42 | # you should judge for yourself, the pros and cons are mentioned at: 43 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 44 | # 45 | # Pods/ 46 | 47 | # Carthage 48 | # 49 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 50 | # Carthage/Checkouts 51 | 52 | Carthage/Build 53 | 54 | # fastlane 55 | # 56 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 57 | # screenshots whenever they are needed. 58 | # For more information about the recommended setup visit: 59 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 60 | 61 | fastlane/report.xml 62 | fastlane/screenshots 63 | -------------------------------------------------------------------------------- /Class/TLSegmentedControl.h: -------------------------------------------------------------------------------- 1 | // 2 | // TLSegmentedControl.h 3 | // TLSegmentedControl 4 | // 5 | // Created by garry on 2017/6/22. 6 | // Copyright © 2017年 com.garry. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class TLSegmentedControl; 12 | 13 | @protocol TLSegmentedControlDelegate 14 | -(void)segmentedControl:(TLSegmentedControl *)segmentedControl didSelectIndex:(NSUInteger)index; 15 | @end 16 | 17 | @interface TLSegmentedControl : UIView 18 | //for indicatorBar scroll 19 | @property(nonatomic,assign)CGFloat offsetX; 20 | //current index 21 | @property(nonatomic,assign)NSUInteger index; 22 | //single page width, default is screen's width 23 | @property(nonatomic,assign)CGFloat pageWidth; 24 | //spacing > 0 && segment's totoal width > segmentedControl.width => scroll = true。default is zero,scroll enable = false 25 | @property(nonatomic,assign)CGFloat spacing; 26 | //only support top & bottom for a moment 27 | @property(nonatomic,assign)UIEdgeInsets padding; 28 | //gradient colors, if set single color indicatorBar will be pure color 29 | @property(nonatomic,strong)NSArray *indicatorBarColor; 30 | //default is {15,3} 31 | @property(nonatomic,assign)CGSize indicatorBarSize; 32 | //default is 0x666666 33 | @property(nonatomic,strong)UIColor *segmentedTitleNormalColor; 34 | //default is 0x333333 35 | @property(nonatomic,strong)UIColor *segmentedTitleSelectedColor; 36 | //default is system 15 37 | @property(nonatomic,strong)UIFont *segmentedTitleFont; 38 | @property(nonatomic,assign)id delegate; 39 | 40 | -(instancetype)initWithTitls:(NSArray *)titles delegate:(id )delegate; 41 | -(instancetype)initWithFrame:(CGRect)frame titls:(NSArray *)titles delegate:(id )delegate; 42 | @end 43 | -------------------------------------------------------------------------------- /Class/TLSegmentedControl.m: -------------------------------------------------------------------------------- 1 | // 2 | // TLSegmentedControl.m 3 | // TLSegmentedControl 4 | // 5 | // Created by garry on 2017/6/22. 6 | // Copyright © 2017年 com.garry. All rights reserved. 7 | // 8 | 9 | 10 | #import "TLSegmentedControl.h" 11 | 12 | #define UIColorFromHEX(hex) [UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16))/255.0 green:((float)((hex & 0xFF00) >> 8))/255.0 blue:((float)(hex & 0xFF))/255.0 alpha:1.0] 13 | 14 | 15 | @interface UIView (TL) 16 | @property (nonatomic, assign) CGFloat x; 17 | @property (nonatomic, assign) CGFloat y; 18 | @property (nonatomic, assign) CGFloat width; 19 | @property (nonatomic, assign) CGFloat height; 20 | @property (nonatomic, assign) CGFloat centerX; 21 | @property (nonatomic, assign) CGFloat centerY; 22 | @property (nonatomic, assign) CGSize size; 23 | @property (nonatomic, assign) CGPoint origin; 24 | @property (nonatomic, assign) CGFloat maxX; 25 | @property (nonatomic, assign) CGFloat maxY; 26 | @end 27 | 28 | @implementation UIView (TL) 29 | - (void)setX:(CGFloat)x { 30 | CGRect frame = self.frame; 31 | frame.origin.x = x; 32 | self.frame = frame; 33 | } 34 | 35 | - (void)setY:(CGFloat)y { 36 | CGRect frame = self.frame; 37 | frame.origin.y = y; 38 | self.frame = frame; 39 | } 40 | 41 | - (void)setMaxX:(CGFloat)maxX { 42 | CGRect frame = self.frame; 43 | CGFloat currMaxX = CGRectGetMaxX(self.frame); 44 | if (maxX > currMaxX) { 45 | self.x += maxX - currMaxX; 46 | } else { 47 | self.x -= maxX - currMaxX; 48 | } 49 | self.frame = frame; 50 | } 51 | 52 | - (void)setMaxY:(CGFloat)maxY { 53 | CGRect frame = self.frame; 54 | CGFloat currMaxY = CGRectGetMaxY(self.frame); 55 | if (maxY > currMaxY) { 56 | self.y += maxY - currMaxY; 57 | } else { 58 | self.y -= maxY - currMaxY; 59 | } 60 | self.frame = frame; 61 | } 62 | 63 | - (CGFloat)maxX { 64 | return CGRectGetMaxX(self.frame); 65 | } 66 | 67 | - (CGFloat)maxY { 68 | return CGRectGetMaxY(self.frame); 69 | } 70 | 71 | - (CGFloat)x { 72 | return self.frame.origin.x; 73 | } 74 | 75 | - (CGFloat)y { 76 | return self.frame.origin.y; 77 | } 78 | 79 | - (void)setCenterX:(CGFloat)centerX { 80 | CGPoint center = self.center; 81 | center.x = centerX; 82 | self.center = center; 83 | } 84 | 85 | - (CGFloat)centerX { 86 | return self.center.x; 87 | } 88 | 89 | - (void)setCenterY:(CGFloat)centerY { 90 | CGPoint center = self.center; 91 | center.y = centerY; 92 | self.center = center; 93 | } 94 | 95 | - (CGFloat)centerY { 96 | return self.center.y; 97 | } 98 | 99 | - (void)setWidth:(CGFloat)width { 100 | CGRect frame = self.frame; 101 | frame.size.width = width; 102 | self.frame = frame; 103 | } 104 | 105 | - (void)setHeight:(CGFloat)height { 106 | CGRect frame = self.frame; 107 | frame.size.height = height; 108 | self.frame = frame; 109 | } 110 | 111 | - (CGFloat)height { 112 | return self.frame.size.height; 113 | } 114 | 115 | - (CGFloat)width { 116 | return self.frame.size.width; 117 | } 118 | 119 | - (void)setSize:(CGSize)size { 120 | CGRect frame = self.frame; 121 | frame.size = size; 122 | self.frame = frame; 123 | } 124 | 125 | - (CGSize)size { 126 | return self.frame.size; 127 | } 128 | 129 | - (void)setOrigin:(CGPoint)origin { 130 | CGRect frame = self.frame; 131 | frame.origin = origin; 132 | self.frame = frame; 133 | } 134 | 135 | - (CGPoint)origin { 136 | return self.frame.origin; 137 | } 138 | @end 139 | 140 | 141 | @interface JLSegmentedButton : UIButton 142 | @end 143 | 144 | @implementation JLSegmentedButton 145 | - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event{ 146 | CGRect bounds = self.bounds; 147 | CGFloat widthDelta = MAX(44.0 - bounds.size.width, 0); 148 | CGFloat heightDelta = MAX(44.0 - bounds.size.height, 0); 149 | bounds = CGRectInset(bounds, -0.5 * widthDelta, -0.5 * heightDelta); 150 | return CGRectContainsPoint(bounds, point); 151 | } 152 | @end 153 | 154 | 155 | @interface TLSegmentedControl () 156 | { 157 | NSUInteger lastIndex; 158 | } 159 | @property(nonatomic,strong)NSArray *segmentedTitles; 160 | @property(nonatomic,strong)UIScrollView *scrollView; 161 | @property(nonatomic,strong)NSMutableArray *btns; 162 | @property(nonatomic,strong)UIView *indicatorBar; 163 | @property(nonatomic,strong)CAGradientLayer *gradientLayer; 164 | @end 165 | 166 | @implementation TLSegmentedControl 167 | -(instancetype)initWithTitls:(NSArray *)titles delegate:(id)delegate { 168 | if (self = [super init]) { 169 | self.delegate = delegate; 170 | self.segmentedTitles = titles; 171 | [self setupViews]; 172 | } 173 | return self; 174 | } 175 | -(instancetype)initWithFrame:(CGRect)frame titls:(NSArray *)titles delegate:(id)delegate { 176 | if (self = [super initWithFrame:frame]) { 177 | self.delegate = delegate; 178 | self.segmentedTitles = titles; 179 | [self setupViews]; 180 | } 181 | return self; 182 | } 183 | 184 | #pragma mark - action 185 | 186 | -(void)segmentSelectedAction:(JLSegmentedButton *)sender { 187 | NSInteger index = [self.btns indexOfObject:sender]; 188 | if (lastIndex == index) { 189 | return; 190 | } 191 | 192 | lastIndex = index; 193 | 194 | for (UIButton *segBtn in self.btns) { 195 | segBtn.selected = NO; 196 | } 197 | sender.selected = YES; 198 | 199 | [UIView animateWithDuration:0.25 animations:^{ 200 | self.indicatorBar.centerX = sender.centerX; 201 | }]; 202 | 203 | [self adjustContentOffsetWithCenterX:sender.centerX]; 204 | 205 | if ([self.delegate respondsToSelector:@selector(segmentedControl:didSelectIndex:)]) { 206 | [self.delegate segmentedControl:self didSelectIndex:index]; 207 | } 208 | } 209 | 210 | #pragma mark - private method 211 | 212 | -(void)setupViews { 213 | self.pageWidth = [UIScreen mainScreen].bounds.size.width; 214 | 215 | [self addSubview:self.scrollView]; 216 | 217 | [self.scrollView addSubview:self.indicatorBar]; 218 | 219 | [self.scrollView.layer addSublayer:self.gradientLayer]; 220 | self.gradientLayer.mask = self.indicatorBar.layer; 221 | 222 | __weak typeof(self)weakSelf = self; 223 | [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidEnterBackgroundNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) { 224 | __strong typeof(weakSelf)strongSelf = weakSelf; 225 | strongSelf.indicatorBar.width = strongSelf.indicatorBarSize.width; 226 | }]; 227 | } 228 | 229 | -(void)adjustContentOffsetWithCenterX:(CGFloat)centerX { 230 | if (self.scrollView.width >= self.scrollView.contentSize.width) { 231 | return; 232 | } 233 | if (centerX > self.scrollView.width / 2) { 234 | if (centerX < self.scrollView.contentSize.width - self.scrollView.width / 2) { 235 | [self.scrollView setContentOffset:CGPointMake(self.indicatorBar.centerX - self.scrollView.width / 2, 0) animated:YES]; 236 | }else { 237 | [self.scrollView setContentOffset:CGPointMake(self.scrollView.contentSize.width - self.scrollView.width, 0) animated:YES]; 238 | } 239 | }else { 240 | [self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES]; 241 | } 242 | } 243 | 244 | #pragma mark - setter 245 | -(void)setPageWidth:(CGFloat)pageWidth { 246 | _pageWidth = pageWidth; 247 | 248 | [self setOffsetX:_offsetX]; 249 | } 250 | -(void)setSegmentedTitles:(NSArray *)segmentedTitles { 251 | _segmentedTitles = segmentedTitles; 252 | 253 | [self.btns removeAllObjects]; 254 | 255 | for (UIView *view in self.scrollView.subviews) { 256 | if ([view isKindOfClass:[JLSegmentedButton class]]) { 257 | [view removeFromSuperview]; 258 | } 259 | } 260 | 261 | NSInteger i = 0; 262 | for (NSString *title in self.segmentedTitles) { 263 | JLSegmentedButton *segBtn = [JLSegmentedButton buttonWithType:UIButtonTypeCustom]; 264 | [segBtn setTitle:title forState:UIControlStateNormal]; 265 | [segBtn setTitleColor:UIColorFromHEX(0x666666) forState:UIControlStateNormal]; 266 | [segBtn setTitleColor:UIColorFromHEX(0x333333) forState:UIControlStateSelected]; 267 | segBtn.titleLabel.font = [UIFont systemFontOfSize:15]; 268 | [segBtn addTarget:self action:@selector(segmentSelectedAction:) forControlEvents:UIControlEventTouchUpInside]; 269 | [segBtn sizeToFit]; 270 | segBtn.bounds = CGRectMake(0, 0, segBtn.titleLabel.intrinsicContentSize.width, segBtn.titleLabel.intrinsicContentSize.height); 271 | 272 | [self.btns addObject:segBtn]; 273 | [self.scrollView addSubview:segBtn]; 274 | i ++ ; 275 | } 276 | 277 | UIButton *firstBtn = [self.btns firstObject]; 278 | firstBtn.selected = YES; 279 | } 280 | -(void)setSegmentedTitleFont:(UIFont *)segmentedTitleFont { 281 | _segmentedTitleFont = segmentedTitleFont; 282 | 283 | for (JLSegmentedButton *btn in self.btns) { 284 | btn.titleLabel.font = segmentedTitleFont; 285 | } 286 | 287 | [self layoutIfNeeded]; 288 | } 289 | -(void)setSegmentedTitleNormalColor:(UIColor *)segmentedTitleNormalColor { 290 | _segmentedTitleNormalColor = segmentedTitleNormalColor; 291 | for (JLSegmentedButton *btn in self.btns) { 292 | [btn setTitleColor:segmentedTitleNormalColor forState:UIControlStateNormal]; 293 | } 294 | } 295 | -(void)setSegmentedTitleSelectedColor:(UIColor *)segmentedTitleSelectedColor { 296 | _segmentedTitleSelectedColor = segmentedTitleSelectedColor; 297 | for (JLSegmentedButton *btn in self.btns) { 298 | [btn setTitleColor:segmentedTitleSelectedColor forState:UIControlStateSelected]; 299 | } 300 | } 301 | -(void)setIndicatorBarSize:(CGSize)indicatorBarSize { 302 | _indicatorBarSize = indicatorBarSize; 303 | self.indicatorBar.size = _indicatorBarSize; 304 | self.indicatorBar.layer.cornerRadius = self.indicatorBar.height / 2; 305 | } 306 | -(void)setIndicatorBarColor:(NSArray *)indicatorBarColor { 307 | _indicatorBarColor = indicatorBarColor; 308 | _gradientLayer.colors = _indicatorBarColor; 309 | } 310 | -(void)setPadding:(UIEdgeInsets)padding { 311 | _padding = padding; 312 | [self layoutIfNeeded]; 313 | } 314 | -(void)setOffsetX:(CGFloat)offsetX { 315 | if (self.pageWidth == 0) { 316 | return; 317 | } 318 | NSInteger index = offsetX / self.pageWidth; 319 | CGFloat rOffset = fmodf(offsetX, self.pageWidth); 320 | 321 | CGFloat centerX = ((UIButton *)self.btns[index]).centerX; 322 | CGFloat nextCenterX = ((UIButton *)self.btns[index + 1 >= self.btns.count ? self.btns.count - 1 : index + 1]).centerX; 323 | CGFloat gapWidth = fabs(nextCenterX - centerX); 324 | 325 | CGFloat bOffsetX = (rOffset / self.pageWidth) * gapWidth; 326 | 327 | if (bOffsetX < gapWidth / 2) { 328 | self.indicatorBar.x = centerX - 7.5; 329 | self.indicatorBar.width = bOffsetX * 2 + 15; 330 | }else { 331 | self.indicatorBar.width = (gapWidth - bOffsetX) * 2 + 15; 332 | self.indicatorBar.x = nextCenterX + 7.5 - self.indicatorBar.width; 333 | } 334 | 335 | } 336 | -(void)setIndex:(NSUInteger)index { 337 | _index = index; 338 | [self segmentSelectedAction:self.btns[index]]; 339 | } 340 | 341 | #pragma mark - getter 342 | 343 | -(UIScrollView *)scrollView { 344 | if (!_scrollView) { 345 | _scrollView = [[UIScrollView alloc] init]; 346 | _scrollView.showsHorizontalScrollIndicator = NO; 347 | } 348 | return _scrollView; 349 | } 350 | -(UIView *)indicatorBar { 351 | if (!_indicatorBar) { 352 | _indicatorBarSize = CGSizeMake(15, 3); 353 | _indicatorBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 3)]; 354 | _indicatorBar.backgroundColor = UIColorFromHEX(0xffd321); 355 | _indicatorBar.layer.cornerRadius = 1.5; 356 | } 357 | return _indicatorBar; 358 | } 359 | -(CAGradientLayer *)gradientLayer { 360 | if (!_gradientLayer) { 361 | _gradientLayer = [[CAGradientLayer alloc] init]; 362 | _gradientLayer.colors = @[(id)[UIColor orangeColor].CGColor,(id)[UIColor redColor].CGColor]; 363 | _gradientLayer.startPoint = CGPointMake(0, 0.5); 364 | _gradientLayer.endPoint = CGPointMake(1, 0.5); 365 | } 366 | return _gradientLayer; 367 | } 368 | -(NSMutableArray *)btns { 369 | if (!_btns) { 370 | _btns = [NSMutableArray array]; 371 | } 372 | return _btns; 373 | } 374 | 375 | #pragma mark - override 376 | 377 | -(void)layoutSubviews { 378 | [super layoutSubviews]; 379 | 380 | self.scrollView.frame = self.bounds; 381 | 382 | CGFloat btnsWidth = 0; 383 | for (JLSegmentedButton *btn in self.btns) { 384 | btnsWidth += btn.intrinsicContentSize.width; 385 | } 386 | 387 | CGFloat spacing = self.spacing == 0 ? (CGRectGetWidth(self.frame) - btnsWidth) / (self.segmentedTitles.count - 1) : self.spacing; 388 | 389 | self.scrollView.contentSize = CGSizeMake(btnsWidth + spacing * (self.btns.count - 1), 0); 390 | self.gradientLayer.frame = CGRectMake(0, 0, self.scrollView.contentSize.width, self.height); 391 | 392 | JLSegmentedButton *lastBtn = nil; 393 | for (int j = 0; j < self.btns.count; j ++ ) { 394 | JLSegmentedButton *segBtn = self.btns[j]; 395 | segBtn.center = CGPointMake(CGRectGetWidth(segBtn.frame) / 2 + (lastBtn ? CGRectGetMaxX(lastBtn.frame) + spacing : 0), segBtn.height / 2 + self.padding.top); 396 | lastBtn = segBtn; 397 | } 398 | 399 | JLSegmentedButton *selectBtn = self.btns[self.index]; 400 | self.indicatorBar.center = CGPointMake(CGRectGetMidX(selectBtn.frame), self.height - CGRectGetHeight(self.indicatorBar.frame) / 2 - self.padding.bottom); 401 | } 402 | @end 403 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 GarryGuo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | TLSegmentedControl 2 | ================== 3 | 4 | # Introduce 5 | * 类似于微博的SegmentedControl 6 | 7 | # System Requirement 8 | * iOS 8.0 or later 9 | * Xcode 8.0 or later 10 | 11 | # Character 12 | * 支持滚动 & 固定宽度两种模式 13 | 14 | # Usage 15 | ``` 16 | TLSegmentedControl *segmentBar = [[TLSegmentedControl alloc] initWithFrame:CGRectMake(0, 0, self.view.width - 100, 44) titls:@[@"Page1",@"Page2",@"Page3",@"Page4",@"Page5",@"Page6"] delegate:self]; 17 | segmentBar.spacing = 20; 18 | segmentBar.padding = UIEdgeInsetsMake(10, 0, 8, 0); 19 | segmentBar.index = 2; 20 | segmentBar.pageWidth = self.view.width / 2; 21 | segmentBar.indicatorBarSize = CGSizeMake(15, 3); 22 | segmentBar.indicatorBarColor = @[(id)[UIColor orangeColor].CGColor,(id)[UIColor redColor].CGColor]; 23 | self.navigationItem.titleView = segmentBar; 24 | ``` 25 | 26 | # Installation with CocoaPods 27 | For TLSegmentedControl, use the following entry in your Podfile: 28 | ``` 29 | pod 'TLSegmentedControl' 30 | ``` 31 | Then run ```pod install``` 32 | 33 | # Images 34 | 35 | -------------------------------------------------------------------------------- /ScreenShot/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timelessg/TLSegmentedControl/c331262bba5d765d06c7449ebcfac0533cb84924/ScreenShot/1.gif -------------------------------------------------------------------------------- /TLSegmentedControl.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint TLSegmentedControl.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | 11 | # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 12 | # 13 | # These will help people to find your library, and whilst it 14 | # can feel like a chore to fill in it's definitely to your advantage. The 15 | # summary should be tweet-length, and the description more in depth. 16 | # 17 | 18 | s.name = "TLSegmentedControl" 19 | s.version = "0.0.3" 20 | s.summary = "The segmentedControl like weibo" 21 | 22 | # This description is used to generate tags and improve search results. 23 | # * Think: What does it do? Why did you write it? What is the focus? 24 | # * Try to keep it short, snappy and to the point. 25 | # * Write the description between the DESC delimiters below. 26 | # * Finally, don't worry about the indent, CocoaPods strips it! 27 | s.description = <<-DESC 28 | It's a segmentedControl like weibo,which implement by Objective-C. 29 | 30 | DESC 31 | 32 | s.homepage = "https://github.com/timelessg/TLSegmentedControl" 33 | # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" 34 | 35 | 36 | # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 37 | # 38 | # Licensing your code is important. See http://choosealicense.com for more info. 39 | # CocoaPods will detect a license file if there is a named LICENSE* 40 | # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. 41 | # 42 | 43 | s.license = "MIT" 44 | # s.license = { :type => "MIT", :file => "FILE_LICENSE" } 45 | 46 | 47 | # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 48 | # 49 | # Specify the authors of the library, with email addresses. Email addresses 50 | # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also 51 | # accepts just a name if you'd rather not provide an email address. 52 | # 53 | # Specify a social_media_url where others can refer to, for example a twitter 54 | # profile URL. 55 | # 56 | 57 | s.author = { "GarryGuo" => "timelessg@hotmail.com" } 58 | # Or just: s.author = "garry" 59 | # s.authors = { "garry" => "timelessg@hotmail.com" } 60 | # s.social_media_url = "http://twitter.com/garry" 61 | 62 | # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 63 | # 64 | # If this Pod runs only on iOS or OS X, then specify the platform and 65 | # the deployment target. You can optionally include the target after the platform. 66 | # 67 | 68 | s.platform = :ios 69 | s.platform = :ios, "5.0" 70 | 71 | # When using multiple platforms 72 | # s.ios.deployment_target = "5.0" 73 | # s.osx.deployment_target = "10.7" 74 | # s.watchos.deployment_target = "2.0" 75 | # s.tvos.deployment_target = "9.0" 76 | 77 | 78 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 79 | # 80 | # Specify the location from where the source should be retrieved. 81 | # Supports git, hg, bzr, svn and HTTP. 82 | # 83 | 84 | s.source = { :git => "https://github.com/timelessg/TLSegmentedControl.git", :tag => "0.0.3" } 85 | 86 | 87 | # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 88 | # 89 | # CocoaPods is smart about how it includes source code. For source files 90 | # giving a folder will include any swift, h, m, mm, c & cpp files. 91 | # For header files it will include any header in the folder. 92 | # Not including the public_header_files will make all headers public. 93 | # 94 | 95 | s.source_files = "Class/*" 96 | 97 | # s.public_header_files = "Classes/**/*.h" 98 | 99 | 100 | # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 101 | # 102 | # A list of resources included with the Pod. These are copied into the 103 | # target bundle with a build phase script. Anything else will be cleaned. 104 | # You can preserve files from being cleaned, please don't preserve 105 | # non-essential files like tests, examples and documentation. 106 | # 107 | 108 | # s.resource = "icon.png" 109 | # s.resources = "Resources/*.png" 110 | 111 | # s.preserve_paths = "FilesToSave", "MoreFilesToSave" 112 | 113 | 114 | # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 115 | # 116 | # Link your library with frameworks, or libraries. Libraries do not include 117 | # the lib prefix of their name. 118 | # 119 | 120 | # s.framework = "SomeFramework" 121 | s.frameworks = 'Foundation', 'UIKit' 122 | 123 | # s.library = "iconv" 124 | # s.libraries = "iconv", "xml2" 125 | 126 | 127 | # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 128 | # 129 | # If your library depends on compiler flags you can set them in the xcconfig hash 130 | # where they will only apply to your library. If you depend on other Podspecs 131 | # you can include multiple dependencies to ensure it works. 132 | 133 | # s.requires_arc = true 134 | 135 | # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } 136 | # s.dependency "JSONKit", "~> 1.4" 137 | 138 | end 139 | -------------------------------------------------------------------------------- /TLSegmentedControl.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4B86BD261EFB932B002BFA13 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B86BD251EFB932B002BFA13 /* main.m */; }; 11 | 4B86BD291EFB932B002BFA13 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B86BD281EFB932B002BFA13 /* AppDelegate.m */; }; 12 | 4B86BD2C1EFB932B002BFA13 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B86BD2B1EFB932B002BFA13 /* ViewController.m */; }; 13 | 4B86BD311EFB932B002BFA13 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B86BD301EFB932B002BFA13 /* Assets.xcassets */; }; 14 | 4B86BD341EFB932B002BFA13 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4B86BD321EFB932B002BFA13 /* LaunchScreen.storyboard */; }; 15 | 4B86BD3E1EFB9372002BFA13 /* TLSegmentedControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B86BD3D1EFB9372002BFA13 /* TLSegmentedControl.m */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 4B86BD211EFB932B002BFA13 /* TLSegmentedControl.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TLSegmentedControl.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | 4B86BD251EFB932B002BFA13 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 21 | 4B86BD271EFB932B002BFA13 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 22 | 4B86BD281EFB932B002BFA13 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 23 | 4B86BD2A1EFB932B002BFA13 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 24 | 4B86BD2B1EFB932B002BFA13 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 25 | 4B86BD301EFB932B002BFA13 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | 4B86BD331EFB932B002BFA13 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | 4B86BD351EFB932B002BFA13 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | 4B86BD3C1EFB9372002BFA13 /* TLSegmentedControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TLSegmentedControl.h; sourceTree = ""; }; 29 | 4B86BD3D1EFB9372002BFA13 /* TLSegmentedControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TLSegmentedControl.m; sourceTree = ""; }; 30 | /* End PBXFileReference section */ 31 | 32 | /* Begin PBXFrameworksBuildPhase section */ 33 | 4B86BD1E1EFB932B002BFA13 /* Frameworks */ = { 34 | isa = PBXFrameworksBuildPhase; 35 | buildActionMask = 2147483647; 36 | files = ( 37 | ); 38 | runOnlyForDeploymentPostprocessing = 0; 39 | }; 40 | /* End PBXFrameworksBuildPhase section */ 41 | 42 | /* Begin PBXGroup section */ 43 | 4B86BD181EFB932B002BFA13 = { 44 | isa = PBXGroup; 45 | children = ( 46 | 4B86BD3B1EFB934C002BFA13 /* Class */, 47 | 4B86BD231EFB932B002BFA13 /* TLSegmentedControl */, 48 | 4B86BD221EFB932B002BFA13 /* Products */, 49 | ); 50 | sourceTree = ""; 51 | }; 52 | 4B86BD221EFB932B002BFA13 /* Products */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | 4B86BD211EFB932B002BFA13 /* TLSegmentedControl.app */, 56 | ); 57 | name = Products; 58 | sourceTree = ""; 59 | }; 60 | 4B86BD231EFB932B002BFA13 /* TLSegmentedControl */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | 4B86BD271EFB932B002BFA13 /* AppDelegate.h */, 64 | 4B86BD281EFB932B002BFA13 /* AppDelegate.m */, 65 | 4B86BD2A1EFB932B002BFA13 /* ViewController.h */, 66 | 4B86BD2B1EFB932B002BFA13 /* ViewController.m */, 67 | 4B86BD301EFB932B002BFA13 /* Assets.xcassets */, 68 | 4B86BD321EFB932B002BFA13 /* LaunchScreen.storyboard */, 69 | 4B86BD351EFB932B002BFA13 /* Info.plist */, 70 | 4B86BD241EFB932B002BFA13 /* Supporting Files */, 71 | ); 72 | path = TLSegmentedControl; 73 | sourceTree = ""; 74 | }; 75 | 4B86BD241EFB932B002BFA13 /* Supporting Files */ = { 76 | isa = PBXGroup; 77 | children = ( 78 | 4B86BD251EFB932B002BFA13 /* main.m */, 79 | ); 80 | name = "Supporting Files"; 81 | sourceTree = ""; 82 | }; 83 | 4B86BD3B1EFB934C002BFA13 /* Class */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | 4B86BD3C1EFB9372002BFA13 /* TLSegmentedControl.h */, 87 | 4B86BD3D1EFB9372002BFA13 /* TLSegmentedControl.m */, 88 | ); 89 | path = Class; 90 | sourceTree = ""; 91 | }; 92 | /* End PBXGroup section */ 93 | 94 | /* Begin PBXNativeTarget section */ 95 | 4B86BD201EFB932B002BFA13 /* TLSegmentedControl */ = { 96 | isa = PBXNativeTarget; 97 | buildConfigurationList = 4B86BD381EFB932B002BFA13 /* Build configuration list for PBXNativeTarget "TLSegmentedControl" */; 98 | buildPhases = ( 99 | 4B86BD1D1EFB932B002BFA13 /* Sources */, 100 | 4B86BD1E1EFB932B002BFA13 /* Frameworks */, 101 | 4B86BD1F1EFB932B002BFA13 /* Resources */, 102 | ); 103 | buildRules = ( 104 | ); 105 | dependencies = ( 106 | ); 107 | name = TLSegmentedControl; 108 | productName = TLSegmentedControl; 109 | productReference = 4B86BD211EFB932B002BFA13 /* TLSegmentedControl.app */; 110 | productType = "com.apple.product-type.application"; 111 | }; 112 | /* End PBXNativeTarget section */ 113 | 114 | /* Begin PBXProject section */ 115 | 4B86BD191EFB932B002BFA13 /* Project object */ = { 116 | isa = PBXProject; 117 | attributes = { 118 | LastUpgradeCheck = 0830; 119 | ORGANIZATIONNAME = com.garry; 120 | TargetAttributes = { 121 | 4B86BD201EFB932B002BFA13 = { 122 | CreatedOnToolsVersion = 8.3.3; 123 | DevelopmentTeam = HLFH2Z48FU; 124 | ProvisioningStyle = Automatic; 125 | }; 126 | }; 127 | }; 128 | buildConfigurationList = 4B86BD1C1EFB932B002BFA13 /* Build configuration list for PBXProject "TLSegmentedControl" */; 129 | compatibilityVersion = "Xcode 3.2"; 130 | developmentRegion = English; 131 | hasScannedForEncodings = 0; 132 | knownRegions = ( 133 | en, 134 | Base, 135 | ); 136 | mainGroup = 4B86BD181EFB932B002BFA13; 137 | productRefGroup = 4B86BD221EFB932B002BFA13 /* Products */; 138 | projectDirPath = ""; 139 | projectRoot = ""; 140 | targets = ( 141 | 4B86BD201EFB932B002BFA13 /* TLSegmentedControl */, 142 | ); 143 | }; 144 | /* End PBXProject section */ 145 | 146 | /* Begin PBXResourcesBuildPhase section */ 147 | 4B86BD1F1EFB932B002BFA13 /* Resources */ = { 148 | isa = PBXResourcesBuildPhase; 149 | buildActionMask = 2147483647; 150 | files = ( 151 | 4B86BD341EFB932B002BFA13 /* LaunchScreen.storyboard in Resources */, 152 | 4B86BD311EFB932B002BFA13 /* Assets.xcassets in Resources */, 153 | ); 154 | runOnlyForDeploymentPostprocessing = 0; 155 | }; 156 | /* End PBXResourcesBuildPhase section */ 157 | 158 | /* Begin PBXSourcesBuildPhase section */ 159 | 4B86BD1D1EFB932B002BFA13 /* Sources */ = { 160 | isa = PBXSourcesBuildPhase; 161 | buildActionMask = 2147483647; 162 | files = ( 163 | 4B86BD3E1EFB9372002BFA13 /* TLSegmentedControl.m in Sources */, 164 | 4B86BD2C1EFB932B002BFA13 /* ViewController.m in Sources */, 165 | 4B86BD291EFB932B002BFA13 /* AppDelegate.m in Sources */, 166 | 4B86BD261EFB932B002BFA13 /* main.m in Sources */, 167 | ); 168 | runOnlyForDeploymentPostprocessing = 0; 169 | }; 170 | /* End PBXSourcesBuildPhase section */ 171 | 172 | /* Begin PBXVariantGroup section */ 173 | 4B86BD321EFB932B002BFA13 /* LaunchScreen.storyboard */ = { 174 | isa = PBXVariantGroup; 175 | children = ( 176 | 4B86BD331EFB932B002BFA13 /* Base */, 177 | ); 178 | name = LaunchScreen.storyboard; 179 | sourceTree = ""; 180 | }; 181 | /* End PBXVariantGroup section */ 182 | 183 | /* Begin XCBuildConfiguration section */ 184 | 4B86BD361EFB932B002BFA13 /* Debug */ = { 185 | isa = XCBuildConfiguration; 186 | buildSettings = { 187 | ALWAYS_SEARCH_USER_PATHS = NO; 188 | CLANG_ANALYZER_NONNULL = YES; 189 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 190 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 191 | CLANG_CXX_LIBRARY = "libc++"; 192 | CLANG_ENABLE_MODULES = YES; 193 | CLANG_ENABLE_OBJC_ARC = YES; 194 | CLANG_WARN_BOOL_CONVERSION = YES; 195 | CLANG_WARN_CONSTANT_CONVERSION = YES; 196 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 197 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 198 | CLANG_WARN_EMPTY_BODY = YES; 199 | CLANG_WARN_ENUM_CONVERSION = YES; 200 | CLANG_WARN_INFINITE_RECURSION = YES; 201 | CLANG_WARN_INT_CONVERSION = YES; 202 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 203 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 204 | CLANG_WARN_UNREACHABLE_CODE = YES; 205 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 206 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 207 | COPY_PHASE_STRIP = NO; 208 | DEBUG_INFORMATION_FORMAT = dwarf; 209 | ENABLE_STRICT_OBJC_MSGSEND = YES; 210 | ENABLE_TESTABILITY = YES; 211 | GCC_C_LANGUAGE_STANDARD = gnu99; 212 | GCC_DYNAMIC_NO_PIC = NO; 213 | GCC_NO_COMMON_BLOCKS = YES; 214 | GCC_OPTIMIZATION_LEVEL = 0; 215 | GCC_PREPROCESSOR_DEFINITIONS = ( 216 | "DEBUG=1", 217 | "$(inherited)", 218 | ); 219 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 220 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 221 | GCC_WARN_UNDECLARED_SELECTOR = YES; 222 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 223 | GCC_WARN_UNUSED_FUNCTION = YES; 224 | GCC_WARN_UNUSED_VARIABLE = YES; 225 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 226 | MTL_ENABLE_DEBUG_INFO = YES; 227 | ONLY_ACTIVE_ARCH = YES; 228 | SDKROOT = iphoneos; 229 | }; 230 | name = Debug; 231 | }; 232 | 4B86BD371EFB932B002BFA13 /* Release */ = { 233 | isa = XCBuildConfiguration; 234 | buildSettings = { 235 | ALWAYS_SEARCH_USER_PATHS = NO; 236 | CLANG_ANALYZER_NONNULL = YES; 237 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 238 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 239 | CLANG_CXX_LIBRARY = "libc++"; 240 | CLANG_ENABLE_MODULES = YES; 241 | CLANG_ENABLE_OBJC_ARC = YES; 242 | CLANG_WARN_BOOL_CONVERSION = YES; 243 | CLANG_WARN_CONSTANT_CONVERSION = YES; 244 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 245 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 246 | CLANG_WARN_EMPTY_BODY = YES; 247 | CLANG_WARN_ENUM_CONVERSION = YES; 248 | CLANG_WARN_INFINITE_RECURSION = YES; 249 | CLANG_WARN_INT_CONVERSION = YES; 250 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 251 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 252 | CLANG_WARN_UNREACHABLE_CODE = YES; 253 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 254 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 255 | COPY_PHASE_STRIP = NO; 256 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 257 | ENABLE_NS_ASSERTIONS = NO; 258 | ENABLE_STRICT_OBJC_MSGSEND = YES; 259 | GCC_C_LANGUAGE_STANDARD = gnu99; 260 | GCC_NO_COMMON_BLOCKS = YES; 261 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 262 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 263 | GCC_WARN_UNDECLARED_SELECTOR = YES; 264 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 265 | GCC_WARN_UNUSED_FUNCTION = YES; 266 | GCC_WARN_UNUSED_VARIABLE = YES; 267 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 268 | MTL_ENABLE_DEBUG_INFO = NO; 269 | SDKROOT = iphoneos; 270 | VALIDATE_PRODUCT = YES; 271 | }; 272 | name = Release; 273 | }; 274 | 4B86BD391EFB932B002BFA13 /* Debug */ = { 275 | isa = XCBuildConfiguration; 276 | buildSettings = { 277 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 278 | DEVELOPMENT_TEAM = HLFH2Z48FU; 279 | INFOPLIST_FILE = TLSegmentedControl/Info.plist; 280 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 281 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 282 | PRODUCT_BUNDLE_IDENTIFIER = com.garry.TLSegmentedControl; 283 | PRODUCT_NAME = "$(TARGET_NAME)"; 284 | TARGETED_DEVICE_FAMILY = 1; 285 | }; 286 | name = Debug; 287 | }; 288 | 4B86BD3A1EFB932B002BFA13 /* Release */ = { 289 | isa = XCBuildConfiguration; 290 | buildSettings = { 291 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 292 | DEVELOPMENT_TEAM = HLFH2Z48FU; 293 | INFOPLIST_FILE = TLSegmentedControl/Info.plist; 294 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 295 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 296 | PRODUCT_BUNDLE_IDENTIFIER = com.garry.TLSegmentedControl; 297 | PRODUCT_NAME = "$(TARGET_NAME)"; 298 | TARGETED_DEVICE_FAMILY = 1; 299 | }; 300 | name = Release; 301 | }; 302 | /* End XCBuildConfiguration section */ 303 | 304 | /* Begin XCConfigurationList section */ 305 | 4B86BD1C1EFB932B002BFA13 /* Build configuration list for PBXProject "TLSegmentedControl" */ = { 306 | isa = XCConfigurationList; 307 | buildConfigurations = ( 308 | 4B86BD361EFB932B002BFA13 /* Debug */, 309 | 4B86BD371EFB932B002BFA13 /* Release */, 310 | ); 311 | defaultConfigurationIsVisible = 0; 312 | defaultConfigurationName = Release; 313 | }; 314 | 4B86BD381EFB932B002BFA13 /* Build configuration list for PBXNativeTarget "TLSegmentedControl" */ = { 315 | isa = XCConfigurationList; 316 | buildConfigurations = ( 317 | 4B86BD391EFB932B002BFA13 /* Debug */, 318 | 4B86BD3A1EFB932B002BFA13 /* Release */, 319 | ); 320 | defaultConfigurationIsVisible = 0; 321 | defaultConfigurationName = Release; 322 | }; 323 | /* End XCConfigurationList section */ 324 | }; 325 | rootObject = 4B86BD191EFB932B002BFA13 /* Project object */; 326 | } 327 | -------------------------------------------------------------------------------- /TLSegmentedControl.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TLSegmentedControl/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // TLSegmentedControl 4 | // 5 | // Created by garry on 2017/6/22. 6 | // Copyright © 2017年 com.garry. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /TLSegmentedControl/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // TLSegmentedControl 4 | // 5 | // Created by garry on 2017/6/22. 6 | // Copyright © 2017年 com.garry. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "ViewController.h" 11 | 12 | @interface AppDelegate () 13 | 14 | @end 15 | 16 | @implementation AppDelegate 17 | 18 | 19 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 20 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 21 | UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]]; 22 | self.window.rootViewController = nav; 23 | [self.window makeKeyAndVisible]; 24 | 25 | return YES; 26 | } 27 | 28 | 29 | - (void)applicationWillResignActive:(UIApplication *)application { 30 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 31 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 32 | } 33 | 34 | 35 | - (void)applicationDidEnterBackground:(UIApplication *)application { 36 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 37 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 38 | } 39 | 40 | 41 | - (void)applicationWillEnterForeground:(UIApplication *)application { 42 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 43 | } 44 | 45 | 46 | - (void)applicationDidBecomeActive:(UIApplication *)application { 47 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 48 | } 49 | 50 | 51 | - (void)applicationWillTerminate:(UIApplication *)application { 52 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 53 | } 54 | 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /TLSegmentedControl/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | } 43 | ], 44 | "info" : { 45 | "version" : 1, 46 | "author" : "xcode" 47 | } 48 | } -------------------------------------------------------------------------------- /TLSegmentedControl/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /TLSegmentedControl/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIRequiredDeviceCapabilities 26 | 27 | armv7 28 | 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /TLSegmentedControl/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // TLSegmentedControl 4 | // 5 | // Created by garry on 2017/6/22. 6 | // Copyright © 2017年 com.garry. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /TLSegmentedControl/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // TLSegmentedControl 4 | // 5 | // Created by garry on 2017/6/22. 6 | // Copyright © 2017年 com.garry. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "TLSegmentedControl.h" 11 | 12 | @interface ViewController () 13 | @property(nonatomic,strong)TLSegmentedControl *segmentBar; 14 | @property(nonatomic,strong)UIScrollView *pageScrollView; 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | 22 | 23 | self.view.backgroundColor = [UIColor whiteColor]; 24 | 25 | self.segmentBar = [[TLSegmentedControl alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width - 100, 44) titls:@[@"Page1",@"Page2",@"Page3",@"Page4",@"Page5",@"Page6"] delegate:self]; 26 | self.segmentBar.spacing = 20; 27 | self.segmentBar.padding = UIEdgeInsetsMake(10, 0, 8, 0); 28 | self.segmentBar.index = 2; 29 | self.segmentBar.pageWidth = self.view.bounds.size.width / 2; 30 | self.segmentBar.indicatorBarSize = CGSizeMake(15, 3); 31 | self.segmentBar.indicatorBarColor = @[(id)[UIColor orangeColor].CGColor,(id)[UIColor redColor].CGColor]; 32 | self.navigationItem.titleView = self.segmentBar; 33 | 34 | 35 | [self.view addSubview:self.pageScrollView]; 36 | self.pageScrollView.frame = CGRectMake(0, 0, self.view.bounds.size.width / 2, 200); 37 | self.pageScrollView.center = CGPointMake(self.view.bounds.size.width / 2, 200); 38 | 39 | self.pageScrollView.contentSize = CGSizeMake(self.view.bounds.size.width * 3, 0); 40 | self.pageScrollView.contentOffset = CGPointMake(self.view.bounds.size.width * 1, 0); 41 | } 42 | -(void)segmentedControl:(TLSegmentedControl *)segmentedControl didSelectIndex:(NSUInteger)index { 43 | self.pageScrollView.contentOffset = CGPointMake(index * (self.view.bounds.size.width / 2), 0); 44 | } 45 | -(void)scrollViewDidScroll:(UIScrollView *)scrollView { 46 | self.segmentBar.offsetX = scrollView.contentOffset.x; 47 | } 48 | -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { 49 | NSInteger index = scrollView.contentOffset.x / scrollView.bounds.size.width; 50 | self.segmentBar.index = index; 51 | } 52 | -(UIScrollView *)pageScrollView { 53 | if (!_pageScrollView) { 54 | _pageScrollView = [[UIScrollView alloc] init]; 55 | _pageScrollView.pagingEnabled = YES; 56 | _pageScrollView.delegate = self; 57 | _pageScrollView.backgroundColor = [UIColor grayColor]; 58 | _pageScrollView.bounces = NO; 59 | _pageScrollView.showsVerticalScrollIndicator = NO; 60 | } 61 | return _pageScrollView; 62 | } 63 | - (void)didReceiveMemoryWarning { 64 | [super didReceiveMemoryWarning]; 65 | // Dispose of any resources that can be recreated. 66 | } 67 | @end 68 | -------------------------------------------------------------------------------- /TLSegmentedControl/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // TLSegmentedControl 4 | // 5 | // Created by garry on 2017/6/22. 6 | // Copyright © 2017年 com.garry. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | --------------------------------------------------------------------------------