标签:
效果如下:
ViewController.h
1 #import <UIKit/UIKit.h> 2 3 @interface ViewController : UIViewController 4 @end
ViewController.m
1 #import "ViewController.h" 2 3 @interface ViewController () 4 - (void)layoutUI; 5 @end 6 7 @implementation ViewController 8 9 - (void)viewDidLoad { 10 [super viewDidLoad]; 11 12 [self layoutUI]; 13 } 14 15 - (void)didReceiveMemoryWarning { 16 [super didReceiveMemoryWarning]; 17 // Dispose of any resources that can be recreated. 18 } 19 20 - (void)layoutUI { 21 UISegmentedControl *smtCContentOffset = [[UISegmentedControl alloc] initWithItems:@[@"First", @"Second", @"Third"]]; 22 smtCContentOffset.tintColor = [UIColor colorWithRed:1.000 green:0.434 blue:0.469 alpha:1.000]; 23 smtCContentOffset.selectedSegmentIndex = 2; 24 smtCContentOffset.momentary = YES; 25 smtCContentOffset.center = self.view.center; 26 27 //修改分段卡标题的位置 28 [smtCContentOffset setContentOffset:CGSizeMake(0, -5) forSegmentAtIndex:0]; 29 [smtCContentOffset setContentOffset:CGSizeMake(0, 5) forSegmentAtIndex:2]; 30 [self.view addSubview:smtCContentOffset]; 31 } 32 33 @end
标签:
原文地址:http://www.cnblogs.com/huangjianwu/p/4579151.html