IOS页面布局 纯代码

1 篇文章 0 订阅
1 篇文章 0 订阅
IOS页面布局:
[objc]  view plain copy print ?
  1. #import "RootViewController.h"  
  2.   
  3. #import "FourViewController.h"  
  4.   
  5. @interface RootViewController ()  
  6.   
  7. @end  
  8.   
  9. @implementation RootViewController  
  10.   
  11. - (void)viewDidLoad {  
  12.     [super viewDidLoad];  
  13.   
  14.     [self addChildViewClass:[OneViewController class] title:@"第一页" imageName:@"1"];  
  15.     [self addChildViewClass:[TowViewController class] title:@"第二页" imageName:@"1"];  
  16.     [self addChildViewClass:[ThreeViewController class] title:@"第三页" imageName:@"1"];  
  17.     [self addChildViewClass:[FourViewController class] title:@"第四页" imageName:@"1"];  
  18. }  
  19.   
  20. - (void)addChildViewClass:(Class)class title:(NSString *)title imageName:(NSString *)imageName  
  21. {  
  22.     UIViewController *viewC = [[class alloc] init];  
  23.     UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:viewC];  
  24.     navC.tabBarItem.title = title;  
  25.     navC.tabBarItem.image = [UIImage imageNamed:imageName];  
  26.     viewC.navigationItem.title = title;  
  27.     [self addChildViewController:navC];  
  28.     [navC release];  
  29.     [viewC release];  
  30. }  
[objc]  view plain copy print ?
  1. #import "FourViewController.h"  
  2.   
  3. @interface FourViewController ()  
  4.   
  5. @end  
  6.   
  7. @implementation FourViewController  
  8.   
  9. - (void)viewDidLoad {  
  10.     [super viewDidLoad];  
  11.     // Do any additional setup after loading the view.  
  12.     self.view.backgroundColor = [UIColor grayColor];  
  13.   
  14.     UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];  
  15.     button.frame = CGRectMake(100100100100);  
  16.     [button addTarget:self action:@selector(actionButton:) forControlEvents:(UIControlEventTouchUpInside)];  
  17.     button.backgroundColor = [UIColor redColor];  
  18.     [button setTitle:@"变色" forState:(UIControlStateNormal)];  
  19.     [self.view addSubview:button];  
  20.     [button release];  
  21. }  
  22.   
  23. // 发送通知:通知的名字必须一样,否者接收不到  
  24. - (void)actionButton:(UIButton *)button  
  25. {  
  26.     [[NSNotificationCenter defaultCenter]postNotificationName:@"NOTICATIONONE" object:nil userInfo:@{@"wang":@"dong"}];  
  27. }  
[objc]  view plain copy print ?
  1. import "AppDelegate.h"  
  2. #import "RootViewController.h"  
  3. @interface AppDelegate ()  
  4.   
  5. @end  
  6.   
  7. @implementation AppDelegate  
  8.   
  9. - (void)dealloc  
  10.   
  11. {  
  12.     // 销毁通知  
  13.     [[NSNotificationCenter defaultCenter]removeObserver:self name:@"NOTICATIONONE" object:nil];  
  14.     [_window release];  
  15.     [super dealloc];  
  16. }  
  17.   
  18. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
  19.     self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];  
  20.     // Override point for customization after application launch.  
  21.     self.window.backgroundColor = [UIColor whiteColor];  
  22.       
  23.     // 1,注册通知  
  24.     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationInfo:) name:@"NOTICATIONONE" object:nil];  
  25.     RootViewController *rootVC = [[RootViewController alloc] init];  
  26.     self.window.rootViewController = rootVC;  
  27.     [rootVC release];  
  28.       
  29.     [self.window makeKeyAndVisible];  
  30.     return YES;  
  31. }  
  32.   
  33. // 2,接收通知的方法  
  34. - (void)notificationInfo:(NSNotification *)notification  
  35. {  
  36.     // 把wiodow的根视图控制器取出来  
  37.     UIViewController *viewC = self.window.rootViewController;  
  38.     //把已经设置window的rootVC 重置为空  
  39.     self.window.rootViewController = nil;  
  40.     // 3,设置皮肤(更改颜色)  
  41.     UINavigationBar *navBar = [UINavigationBar appearance];  
  42.         [navBar setBarTintColor:[UIColor redColor]];  
  43.     UITabBar *tabBar = [UITabBar appearance];  
  44.     [tabBar setBarTintColor:[UIColor redColor]];  
  45.     // 重新赋值window的根视图控制器  
  46.     self.window.rootViewController = viewC;  
  47.      
  48.     // 接收通知里携带的参数  
  49.     NSDictionary *dic = notification.userInfo;  
  50.       
  51.     NSLog(@"收到通知--%@ 通知名字--%@ 参数_-%@",dic,notification.name,notification.object);  
  52. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值