#import "AppDelegate.h"
#import "HomeViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
HomeViewController *hvc=[[HomeViewController alloc]init];
UINavigationController *nc=[[UINavigationController alloc]initWithRootViewController:hvc];
self.window.rootViewController=nc;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
#import "HomeViewController.h"
#import "OtherViewController.h"
@interface HomeViewController ()
{
NSArray *nameArr;
}
@end
@implementation HomeViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
OtherViewController *svc = [[OtherViewController alloc]init];
//通过页面找到nc,让nc推出一个新的页面
[self.navigationController pushViewController:svc animated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"header_bg"] forBarMetrics:UIBarMetricsDefault];
UIImageView *iv=[[UIImageView alloc]initWithFrame:self.view.frame];
[iv setImage:[UIImage imageNamed:@"main_background"]];
[self.view addSubview:iv];
UIImageView *bcv=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
[bcv setImage:[UIImage imageNamed:@"logo_title"]];
self.navigationItem.titleView = bcv;
UIButton *btnl=[UIButton buttonWithType:UIButtonTypeSystem];
btnl.frame=CGRectMake(0, 0, 33, 30);
[btnl setBackgroundImage:[UIImage imageNamed:@"main_left_nav"] forState:UIControlStateNormal];
[btnl addTarget:self action:@selector(leftClick) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barl=[[UIBarButtonItem alloc]initWithCustomView:btnl];
self.navigationItem.leftBarButtonItem=barl;
UIButton *btnr=[UIButton buttonWithType:UIButtonTypeSystem];
btnr.frame=CGRectMake(0, 0, 48,29);
[btnr setBackgroundImage:[UIImage imageNamed:@"main_right_nav"] forState:UIControlStateNormal];
[btnr addTarget:self action:@selector(leftClick) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barr=[[UIBarButtonItem alloc]initWithCustomView:btnr];
self.navigationItem.rightBarButtonItem=barr;
UIView *zj=[[UIView alloc]initWithFrame:CGRectMake(25, 50, 270, 270)];
//zj.backgroundColor=[UIColor cyanColor];
zj.userInteractionEnabled=YES;
[self.view addSubview:zj];
NSArray *imgarr=[NSArray arrayWithObjects:[UIImage imageNamed:@"gerenzhuye"],[UIImage imageNamed:@"xinxianshi"],[UIImage imageNamed:@"haoyou"],[UIImage imageNamed:@"yingyong"],[UIImage imageNamed:@"weizhi"],[UIImage imageNamed:@"xiangce"],[UIImage imageNamed:@"sousuo"],[UIImage imageNamed:@"liaotian"],[UIImage imageNamed:@"zhanneixin"], nil];
//NSArray *textarr=[NSArray arrayWithObjects:@"个人主页",@"新鲜事", @"好友", @"应用", @"位置", @"相册", @"搜索", @"聊天", @"站内信", nil];
nameArr = @[@"个人主页",@"新鲜事",@"好友",@"应用",@"位置",@"相册",@"搜索",@"聊天",@"站内信"];
int k=0;
for (int i=0; i<3; i++) {
for (int j=0; j<3; j++) {
UIButton *btn=[[UIButton alloc]init];
btn.frame=CGRectMake(j*90, i*90, 85, 85);
[btn setImage:[imgarr objectAtIndex:k] forState:UIControlStateNormal];
btn.tag=100+k;
[btn addTarget:self action:@selector(Click:) forControlEvents:UIControlEventTouchUpInside];
UILabel *label=[[UILabel alloc]init];
label.textAlignment=NSTextAlignmentCenter;
label.frame=CGRectMake(j*90, i*90+42, 85, 85);
label.text=[nameArr objectAtIndex:k];
k++;
[zj addSubview:label];
[zj addSubview:btn];
}
}
}
-(void)leftClick
{
NSLog(@"%s",__func__);
}
-(void)Click:(UIButton *)sender
{
OtherViewController *ovc=[[OtherViewController alloc]init];
ovc.navigationItem.title=[nameArr objectAtIndex:sender.tag-100];
[self.navigationController pushViewController:ovc animated:YES];
}
#import "OtherViewController.h"
@interface OtherViewController ()
@end
@implementation OtherViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor whiteColor];
UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:nil action:nil];
self.navigationItem.rightBarButtonItem=right;
UIImageView *iv=[[UIImageView alloc]initWithFrame:self.view.frame];
[iv setImage:[UIImage imageNamed:@"main_background_5"]];
[self.view addSubview:iv];
}