#import "AppDelegate.h"
#import "FirstViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
_window.backgroundColor = [UIColor whiteColor];
[_window makeKeyAndVisible];
//创建三级控制器
FirstViewController *firstCtrl = [[FirstViewController alloc] init];
UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:firstCtrl];
_window.rootViewController = navCtrl;
return YES;
}
在FirstViewController.h中导入
#import "SecondViewController.h"
#import "ThirdViewController.h"
#define KScreenW [UIScreen mainScreen].bounds.size.width
#define KScreenH [UIScreen mainScreen].bounds.size.height
@interface FirstViewController ()
@end
@implementation FirstViewController
- (void)viewDidLoad {
[super viewDidLoad];
//设置导航栏显示的图片
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar_bg_normal"] forBarMetrics:UIBarMetricsDefault];
// 设置导航栏标题
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 90, 50)];
titleLabel.text = @"乔布斯的微博";
titleLabel.textColor = [UIColor whiteColor];
self.navigationItem.titleView = titleLabel;
[titleLabel release];
//设置背景图
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, KScreenH)];
imgView.image = [UIImage imageNamed:@"bj.jpg"];
[self.view addSubview:imgView];
[imgView release];
// 设置一个导航按钮,在上面创建一个视图来控制按钮的距离
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 34)];
UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithCustomView:view];
self.navigationItem.leftBarButtonItem = barItem;
// 左侧按钮(编辑)
UIButton *leftButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
leftButton1.frame = CGRectMake(0, 0, 33, 32);
[leftButton1 setBackgroundImage:[UIImage imageNamed:@"write"] forState:UIControlStateNormal];
[leftButton1 addTarget:self action:@selector(leftButton1Action) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:leftButton1];
// 左侧按钮(搜索)
UIButton *leftButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
leftButton2.frame = CGRectMake(60, 0, 33, 32);
[leftButton2 setBackgroundImage:[UIImage imageNamed:@"btn_search"] forState:UIControlStateNormal];
[leftButton2 addTarget:self action:@selector(leftButton2Action) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:leftButton2];
// 刷新按钮
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
rightButton.frame = CGRectMake(0, 0, 35, 33);
[rightButton setBackgroundImage:[UIImage imageNamed:@"刷新"] forState:UIControlStateNormal];
[rightButton setBackgroundImage:[UIImage imageNamed:@"刷新选中"] forState:UIControlStateHighlighted];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
}
- (void)leftButton1Action {
SecondViewController *secondCtrl = [[SecondViewController alloc] init];
[self presentViewController:secondCtrl animated:YES completion:nil]
;
[secondCtrl release];
}
- (void)leftButton2Action {
ThirdViewController *thirdCtrl = [[ThirdViewController alloc] init];
[self.navigationController pushViewController:thirdCtrl animated:YES];
[thirdCtrl release];
}
在SecondViewController.h
#define KScreenW [UIScreen mainScreen].bounds.size.width
#define KScreenH [UIScreen mainScreen].bounds.size.height
@interface SecondViewController ()
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 设置背景图
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, KScreenH)];
imgView.image = [UIImage imageNamed:@"bj.jpg"];
[self.view addSubview:imgView];
[imgView release];
UIImageView *imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, 64)];
imgView1.image = [UIImage imageNamed:@"navbar_bg_normal"];
[self.view addSubview:imgView1];
// 设置导航栏标题
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(160, 15, 90, 50)];
titleLabel.text = @"写微博";
titleLabel.textColor = [UIColor whiteColor];
// self.navigationItem.titleView = titleLabel;
// [titleLabel release];
[imgView1 addSubview:titleLabel];
// 返回键
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(0, 25, 68, 33);
[button1 setTitle:@"返回" forState:UIControlStateNormal];
[button1 setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
[button1 setBackgroundImage:[UIImage imageNamed:@"back_on"] forState:UIControlStateHighlighted];
[button1 addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
[imgView1 addSubview:button1];
imgView1.userInteractionEnabled = YES;
// 文本框
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 74, KScreenW - 20, 150)];
textView.font = [UIFont systemFontOfSize:20];
[self.view addSubview:textView];
// 发送
UIButton *sendButton = [UIButton buttonWithType:UIButtonTypeCustom];
sendButton.frame = CGRectMake(10, 240, 97, 45);
[sendButton setTitle:@"发送" forState:UIControlStateNormal];
[sendButton setBackgroundImage:[UIImage imageNamed:@"登陆"] forState:UIControlStateNormal];
[sendButton setBackgroundImage:[UIImage imageNamed:@"登陆_h"] forState:UIControlStateHighlighted];
[self.view addSubview:sendButton];
}
- (void)buttonAction {
[self dismissViewControllerAnimated:YES completion:nil];
}
在ThirdViewController.h中导入
#import "FourthViewController.h"
#define KScreenW [UIScreen mainScreen].bounds.size.width
#define KScreenH [UIScreen mainScreen].bounds.size.height
@interface ThirdViewController ()
@end
@implementation ThirdViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 设置背景图
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, KScreenH)];
imgView.image = [UIImage imageNamed:@"bj.jpg"];
[self.view addSubview:imgView];
[imgView release];
// 设置导航栏标题
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 90, 50)];
titleLabel.text = @"图片新闻";
titleLabel.textColor = [UIColor whiteColor];
self.navigationItem.titleView = titleLabel;
[titleLabel release];
// 返回键
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(0, 0, 68, 33);
[button1 setTitle:@"返回" forState:UIControlStateNormal];
[button1 setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
[button1 setBackgroundImage:[UIImage imageNamed:@"back_on"] forState:UIControlStateHighlighted];
[button1 addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:button1];
self.navigationItem.leftBarButtonItem = backItem;
[backItem release];
UIButton *imgButton = [UIButton buttonWithType:UIButtonTypeCustom];
imgButton.frame = CGRectMake(10, 10, 90, 90);
imgButton.tag = 101;
[imgButton setImage:[UIImage imageNamed:@"20120618100.jpg"] forState:UIControlStateNormal];
[imgButton addTarget:self action:@selector(imgButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:imgButton];
UIButton *imgButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
imgButton1.frame = CGRectMake(110, 10, 90, 90);
imgButton1.tag = 102;
[imgButton1 setImage:[UIImage imageNamed:@"20120618101.jpg"] forState:UIControlStateNormal];
[imgButton1 addTarget:self action:@selector(imgButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:imgButton1];
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationController.toolbarHidden = YES;
self.navigationController.navigationBar.translucent = NO;
}
- (void)buttonAction {
[self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)imgButtonAction:(UIButton *)button{
// if (button.tag == 101) {
//
// FourthViewController *fourthCtrl = [[FourthViewController alloc] init];
// [self.navigationController pushViewController:fourthCtrl animated:YES];
// [fourthCtrl release];
//
// }else if (button.tag == 102){
// FiveViewController *fiveCtrl = [[FiveViewController alloc] init];
// [self.navigationController pushViewController:fiveCtrl animated:YES];
// [fiveCtrl release];
// }
UIImage *image = [button imageForState:UIControlStateNormal];
FourthViewController *fourCtrl = [[FourthViewController alloc] init];
fourCtrl.image = image;
[self.navigationController pushViewController:fourCtrl animated:YES];
}
在FourthViewController.h中
#define KScreenW [UIScreen mainScreen].bounds.size.width
#define KScreenH [UIScreen mainScreen].bounds.size.height
@interface FourthViewController ()
@end
@implementation FourthViewController
- (void)viewDidLoad {
[super viewDidLoad];
// // 设置背景图
// UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, KScreenH)];
// imgView.image = [UIImage imageNamed:@"20120618100.jpg"];
// [self.view addSubview:imgView];
// [imgView release];
//
// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 90, 50)];
// titleLabel.text = @"无限图片";
// titleLabel.textColor = [UIColor whiteColor];
// self.navigationItem.titleView = titleLabel;
// [titleLabel release];
//
// UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
// button1.frame = CGRectMake(0, 0, 68, 33);
// [button1 setTitle:@"图片新闻" forState:UIControlStateNormal];
// button1.titleLabel.font = [UIFont systemFontOfSize:12];
// [button1 setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
// [button1 setBackgroundImage:[UIImage imageNamed:@"back_on"] forState:UIControlStateHighlighted];
// [button1 addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
// UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:button1];
// self.navigationItem.leftBarButtonItem = backItem;
// [backItem release];
//
// UIVisualEffectView *visualEffectView1 = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
// visualEffectView1.frame = CGRectMake(0, KScreenH -130, KScreenW, 90);
// visualEffectView1.alpha = .6;
// [self.view addSubview:visualEffectView1];
//
// UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, KScreenH -130, KScreenW, 90)];
// label.numberOfLines = 4;
// label.textColor = [UIColor whiteColor];
// label.text = @"神九和天宫对接后,航天员在太空中拥有一套两居室,吃饭在神九轨道舱内,睡觉以及一系列的科学实验则是在天宫里完成,作息时间基本和北京时间一致。";
// [self.view addSubview:label];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
imageView.image = self.image;
[self.view addSubview:imageView];
self.navigationController.toolbarHidden = NO;
self.navigationController.navigationBar.translucent = YES;
}
- (void)buttonAction {
[self.navigationController popViewControllerAnimated:YES];
}