1 Star 0 Fork 0

AliliWl / MyAllDemo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
NotificationViewController.m 2.41 KB
一键复制 编辑 原始数据 按行查看 历史
AliliWl 提交于 2014-12-02 12:02 . 1
//
// NotificationViewController.m
// MyAllDemo
//
// Created by mac on 14-10-14.
// Copyright (c) 2014年 huacheng. All rights reserved.
//
#import "NotificationViewController.h"
#import "SendNotificationViewController.h"
@interface NotificationViewController ()
@end
@implementation NotificationViewController
- (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.
UIButton *button1=[[UIButton alloc] initWithFrame:CGRectMake(110, 100, 100, 30)];
[button1 setTitle:@"红色" forState:UIControlStateNormal];
button1.backgroundColor=[UIColor redColor];
[button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button1 addTarget:self action:@selector(redChange) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button1];
//注册通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doChange:) name:@"notificationName" object:nil];
}
- (void)redChange
{
SendNotificationViewController *next = [[SendNotificationViewController alloc] init];
[self.navigationController pushViewController:next animated:YES];
// //发送通知
// NSDictionary *dict=[NSDictionary dictionaryWithObject:@"redcolor" forKey:@"color"];
// [[NSNotificationCenter defaultCenter] postNotificationName:@"notificationName" object:self userInfo:dict];
}
- (void)yellowChange
{
// //发送通知
// NSDictionary *dict1=[NSDictionary dictionaryWithObject:@"yellowcolor" forKey:@"color"];
// [[NSNotificationCenter defaultCenter] postNotificationName:@"notificationName" object:self userInfo:dict1];
}
- (void)doChange:(NSNotification *)notification
{
NSDictionary *dict2=[notification userInfo];
NSString *colorstr=[dict2 objectForKey:@"color"];
UIColor *color=nil;
if ([colorstr isEqualToString:@"redcolor"])
{
color=[UIColor redColor];
}
if([colorstr isEqualToString:@"yellowcolor"])
{
color=[UIColor yellowColor];
}
self.view.backgroundColor=color;
}
- (void)btnClick
{
// ChangeColorViewController *chage=[[ChangeColorViewController alloc] initWithNibName:@"ChangeColorViewController" bundle:nil];
}
@end
Objective-C
1
https://gitee.com/AliliWl/MyAllDemo.git
git@gitee.com:AliliWl/MyAllDemo.git
AliliWl
MyAllDemo
MyAllDemo
master

搜索帮助