2013-01-07 63 views

回答

3
// Instantiate as usual 
NSArray *items = [NSArray arrayWithObjects:@"first", @"second", [UIImage imageNamed:@"image.png"], nil]; 
MCSegmentedControl *segmentedControl = [[MCSegmentedControl alloc] initWithItems:items]; 

// set frame, add to view, set target and action for value change as usual 
segmentedControl.frame = CGRectMake(10.0f, 10.0f, 300.0f, 44.0f); 
[self.view addSubview:segmentedControl]; 
[segmentedControl addTarget:self action:@selector(segmentedControlDidChange:) forControlEvents:UIControlEventValueChanged]; 

// Set a tint color 
segmentedControl.tintColor = [UIColor orangeColor]; 

// Customize font and items color 
segmentedControl.selectedItemColor = [UIColor yellowColor]; 
segmentedControl.unselectedItemColor = [UIColor darkGrayColor]; 

如果您使用Interface Builder,添加一個普通UISegmentedControl,將其作爲MCSegmentedControl類的身份檢查,在檢查的屬性設置的色調。

目前,動畫及以下UISegmentedControl方法不支持:

- (void)setWidth:(CGFloat)width forSegmentAtIndex:(NSUInteger)segment; 
- (void)setContentOffset:(CGSize)offset forSegmentAtIndex:(NSUInteger)segment 

以下是文件:

MCSegmentedControl.zip

+0

感謝您的幫助 – coder1010

相關問題