/***********************************************************************************/
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
-(void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window =[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor =[UIColor grayColor];
[self.window makeKeyAndVisible];
[_window release];
UIViewController *vc =[[UIViewController alloc] init];
self.window.rootViewController=vc;
[vc release];
// UILabel *label =[[UILabel alloc] initWithFrame:CGRectMake(50, 50,100, 50)];
// label.backgroundColor =[UIColor yellowColor];
// [self.window addSubview:label];
// [label release];
// label.text =@"程锦乐"; //添加汉字
// label.textAlignment =1; //居中对齐
// label.textColor =[UIColor blackColor]; //设置字体颜色
// label.font=[UIFont systemFontOfSize:20]; //字体大小
// label.shadowColor =[UIColor greenColor]; //阴影颜色
// label.shadowOffset = CGSizeMake(5, 5); //阴影大小
/// 加边框
//
// label.layer.borderWidth =1;
///加弧度
// label.layer.cornerRadius =50;
///把多余的框(部分)隐藏掉
// label.layer.masksToBounds =YES;
/// UIButton
// UIButton *button =[[UIButton alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
// button.backgroundColor =[UIColor orangeColor];
// [self.window addSubview:button];
// [button release];
// /// UIButton提供了通过便利构造器创建的方法
// UIButton *button =[UIButton buttonWithType:UIButtonTypeSystem];
// ///设置尺寸
// button.frame =CGRectMake(100, 100, 150, 50);
// button.backgroundColor =[UIColor redColor];
// [self.window addSubview:button];
// ///通过这种方法创建不需要release
// button.layer.borderWidth =1; //边框
// button.layer.cornerRadius = 50; //弧度
// /// 给 button设置标题
// [button setTitle:@"程锦乐" forState:UIControlStateNormal];
// /// 标题颜色
// [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
// /// 标题大小
// button.titleLabel.font =[UIFont systemFontOfSize:25];
// /// button 的点击方法
// [button addTarget:self action:@selector(cilick:) forControlEvents:UIControlEventTouchUpInside ];
//
// UIButton *button1 =[UIButton buttonWithType:UIButtonTypeSystem];
// button1.frame =CGRectMake(100,150 , 150, 50);
// button1.backgroundColor =[UIColor greenColor];
// button1.layer.borderWidth =2;
// button1.layer.cornerRadius = 48;
// [self.window addSubview:button1];
// [button1 setTitle:@"大地瓜" forState:UIControlStateNormal];
// [button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
// button1.titleLabel.font =[UIFont systemFontOfSize:25];
// [button1 addTarget:self action:@selector(cilick:) forControlEvents:UIControlEventTouchUpInside];
// UIButton *button1 =[UIButton buttonWithType:UIButtonTypeSystem];
// button1.frame =CGRectMake(100, 100, 150, 50);
// button1.backgroundColor =[UIColor orangeColor];
// button1.layer.borderWidth= 1; //加边框
// button1.layer.cornerRadius =25; //加弧度
// [self.window addSubview:button1];
///设置背景图片
///第一种方法
// [button1 setBackgroundImage:[UIImage imageNamed:@"BtnOff.png"] forState:UIControlStateNormal];
///第二种方法 UIButtonTypeSystem 换成 UIButtonTypeCustom
UIButton *button2 =[UIButton buttonWithType:UIButtonTypeCustom];
button2.frame=CGRectMake(100, 150, 150, 50);
[self.window addSubview:button2];
button2.layer.borderWidth=1; //加边框
button2.layer.cornerRadius=25; //加弧度
[button2 setImage:[UIImage imageNamed:@"BtnOff.png"] forState:UIControlStateNormal];
[button2 addTarget:self action:@selector(changeImage:) forControlEvents:UIControlEventTouchUpInside];
// [button2 setTitle:@"你好" forState:UIControlStateNormal];
// [button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//custom 是自定义的button,跟system没什么太大区别,但是在设置图片上有区别,一个是setBackGroudImgae和setImage有区别,在一个就是custom设置标题还需要额外设置标题颜色
return YES;
}
-(void)cilick:(UIButton *)button
{ //这个参数button就是触发方法对应的那个对象
// NSLog(@"测试一下");
// NSLog(@"%@",button.currentTitle);
//点击button更换标题
if ([button.currentTitle isEqualToString:@"程锦乐"])
{
[button setTitle:@"笑哈哈" forState:UIControlStateNormal];
}else
if ([button.currentTitle isEqualToString:@"笑哈哈"])
{
[button setTitle:@"程锦乐" forState:UIControlStateNormal];
}
}
-(void)changeImage:(UIButton *)button
{
NSLog(@"%d",button.selected);
if (button.selected == NO)
{
[button setImage:[UIImage imageNamed:@"BtnOn.png"] forState:UIControlStateNormal];
}else
{
[button setImage:[UIImage imageNamed:@"BtnOff.png"] forState:UIControlStateNormal];
}
button.selected = !button.selected;
}