//
// CustomSegmentedViewController.m
// CustomSegmented
//
// Created by qian cheng on 12-1-12.
// Copyright 2012 __MyCompanyName__. All rights reserved.
//
#import "CustomSegmentedViewController.h"
#import "CQSegmentControl.h"
@implementation CustomSegmentedViewController
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
// Image And title
NSArray *titleItems = [NSArray arrayWithObjects:NSLocalizedStringFromTable(@"Boy", @"XXXX...这就不写了", nil),
NSLocalizedStringFromTable(@"Girl", @"XXXX...这就不写了", nil), nil];
UIImage *normal_left = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"left_normal" ofType:@"png"]];
UIImage *normal_right = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"right_normal" ofType:@"png"]];
NSMutableArray *unselectImages = [[NSMutableArray alloc]initWithObjects:normal_left, normal_right, nil];
[normal_left release];
[normal_right release];
UIImage *select_left = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"left_press" ofType:@"png"]];
UIImage *select_right = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"right_press" ofType:@"png"]];
NSMutableArray *selectImages = [[NSMutableArray alloc]initWithObjects: select_left, select_right, nil];
[select_left release];
[select_right release];
CQSegmentControl *_segmentedControl= [[CQSegmentControl alloc] initWithItemsAndStype:titleItems stype:TitleAndImageSegmented];
for (UIView *subView in _segmentedControl.subviews)
{
[subView removeFromSuperview];
}
_segmentedControl.normalImageItems = unselectImages;
[unselectImages release];
_segmentedControl.highlightImageItems = selectImages;
[selectImages release];
_segmentedControl.selectedSegmentIndex = 1;
_segmentedControl.frame = CGRectMake(100.0f, 80.0f, 130.0f, 30.0f);
_segmentedControl.selectedItemColor = [UIColor whiteColor];
_segmentedControl.unselectedItemColor = [UIColor grayColor];
[_segmentedControl addTarget:self action:@selector(test:) forControlEvents:UIControlEventValueChanged];
_segmentedControl.font = [UIFont systemFontOfSize:14];
[self.view addSubview:_segmentedControl];
[_segmentedControl release];
//Title
NSArray *titleItem = [NSArray arrayWithObjects:NSLocalizedStringFromTable(@"Boy", @"XXXX...这就不写了", nil),
NSLocalizedStringFromTable(@"Girl", @"XXXX...这就不写了", nil), nil];
CQSegmentControl *_segmented= [[CQSegmentControl alloc] initWithItemsAndStype:titleItem stype:NormalSegmented];
for (UIView *subView in _segmented.subviews)
{
[subView removeFromSuperview];
}
_segmented.selectedSegmentIndex = 1;
_segmented.frame = CGRectMake(100.0f, 180.0f, 130.0f, 30.0f);
_segmented.selectedItemColor = [UIColor whiteColor];
_segmented.unselectedItemColor = [UIColor blueColor];
[_segmented addTarget:self action:@selector(test:) forControlEvents:UIControlEventValueChanged];
_segmented.font = [UIFont systemFontOfSize:14];
[self.view addSubview:_segmented];
[_segmented release];
//image
UIImage *normal_left_1 = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"left_normal" ofType:@"png"]];
UIImage *normal_right_2 = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"right_normal" ofType:@"png"]];
NSMutableArray *test = [[NSMutableArray alloc]initWithObjects:normal_left, normal_right, nil];
[normal_left_1 release];
[normal_right_2 release];
CQSegmentControl *_segmented_test= [[CQSegmentControl alloc] initWithItemsAndStype:test stype:NormalSegmented];
[test release];
for (UIView *subView in _segmented_test.subviews)
{
[subView removeFromSuperview];
}
_segmented_test.selectedSegmentIndex = 1;
_segmented_test.frame = CGRectMake(100.0f, 280.0f, 130.0f, 30.0f);
_segmented_test.selectedItemColor = [UIColor yellowColor];
_segmented_test.unselectedItemColor = [UIColor orangeColor];
[_segmented_test addTarget:self action:@selector(test:) forControlEvents:UIControlEventValueChanged];
_segmented_test.font = [UIFont systemFontOfSize:14];
[self.view addSubview:_segmented_test];
[_segmented_test release];
}
- (void)test:(id)sender
{
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
// CustomSegmentedViewController.m
// CustomSegmented
//
// Created by qian cheng on 12-1-12.
// Copyright 2012 __MyCompanyName__. All rights reserved.
//
#import "CustomSegmentedViewController.h"
#import "CQSegmentControl.h"
@implementation CustomSegmentedViewController
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
// Image And title
NSArray *titleItems = [NSArray arrayWithObjects:NSLocalizedStringFromTable(@"Boy", @"XXXX...这就不写了", nil),
NSLocalizedStringFromTable(@"Girl", @"XXXX...这就不写了", nil), nil];
UIImage *normal_left = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"left_normal" ofType:@"png"]];
UIImage *normal_right = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"right_normal" ofType:@"png"]];
NSMutableArray *unselectImages = [[NSMutableArray alloc]initWithObjects:normal_left, normal_right, nil];
[normal_left release];
[normal_right release];
UIImage *select_left = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"left_press" ofType:@"png"]];
UIImage *select_right = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"right_press" ofType:@"png"]];
NSMutableArray *selectImages = [[NSMutableArray alloc]initWithObjects: select_left, select_right, nil];
[select_left release];
[select_right release];
CQSegmentControl *_segmentedControl= [[CQSegmentControl alloc] initWithItemsAndStype:titleItems stype:TitleAndImageSegmented];
for (UIView *subView in _segmentedControl.subviews)
{
[subView removeFromSuperview];
}
_segmentedControl.normalImageItems = unselectImages;
[unselectImages release];
_segmentedControl.highlightImageItems = selectImages;
[selectImages release];
_segmentedControl.selectedSegmentIndex = 1;
_segmentedControl.frame = CGRectMake(100.0f, 80.0f, 130.0f, 30.0f);
_segmentedControl.selectedItemColor = [UIColor whiteColor];
_segmentedControl.unselectedItemColor = [UIColor grayColor];
[_segmentedControl addTarget:self action:@selector(test:) forControlEvents:UIControlEventValueChanged];
_segmentedControl.font = [UIFont systemFontOfSize:14];
[self.view addSubview:_segmentedControl];
[_segmentedControl release];
//Title
NSArray *titleItem = [NSArray arrayWithObjects:NSLocalizedStringFromTable(@"Boy", @"XXXX...这就不写了", nil),
NSLocalizedStringFromTable(@"Girl", @"XXXX...这就不写了", nil), nil];
CQSegmentControl *_segmented= [[CQSegmentControl alloc] initWithItemsAndStype:titleItem stype:NormalSegmented];
for (UIView *subView in _segmented.subviews)
{
[subView removeFromSuperview];
}
_segmented.selectedSegmentIndex = 1;
_segmented.frame = CGRectMake(100.0f, 180.0f, 130.0f, 30.0f);
_segmented.selectedItemColor = [UIColor whiteColor];
_segmented.unselectedItemColor = [UIColor blueColor];
[_segmented addTarget:self action:@selector(test:) forControlEvents:UIControlEventValueChanged];
_segmented.font = [UIFont systemFontOfSize:14];
[self.view addSubview:_segmented];
[_segmented release];
//image
UIImage *normal_left_1 = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"left_normal" ofType:@"png"]];
UIImage *normal_right_2 = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"right_normal" ofType:@"png"]];
NSMutableArray *test = [[NSMutableArray alloc]initWithObjects:normal_left, normal_right, nil];
[normal_left_1 release];
[normal_right_2 release];
CQSegmentControl *_segmented_test= [[CQSegmentControl alloc] initWithItemsAndStype:test stype:NormalSegmented];
[test release];
for (UIView *subView in _segmented_test.subviews)
{
[subView removeFromSuperview];
}
_segmented_test.selectedSegmentIndex = 1;
_segmented_test.frame = CGRectMake(100.0f, 280.0f, 130.0f, 30.0f);
_segmented_test.selectedItemColor = [UIColor yellowColor];
_segmented_test.unselectedItemColor = [UIColor orangeColor];
[_segmented_test addTarget:self action:@selector(test:) forControlEvents:UIControlEventValueChanged];
_segmented_test.font = [UIFont systemFontOfSize:14];
[self.view addSubview:_segmented_test];
[_segmented_test release];
}
- (void)test:(id)sender
{
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end