iOS UI02_UIButton

//

//  AppDelegate.m

//  UI02_UIButton

//

//  Created by dllo on 15/7/29.

//  Copyright (c) 2015年 zhozhicheng. All rights reserved.

//

#import "AppDelegate.h"

@interface
AppDelegate ()

@property(nonatomic,assign)BOOL isSelected;

@property(nonatomic,assign)BOOL isClick

@end

@implementation AppDelegate

-(void)dealloc

{

[_window
release];

[super
dealloc];

}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {

self.window = [[UIWindow
alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];

// Override point for customization after application launch.

self.window.backgroundColor = [UIColor
whiteColor];

[self.window
makeKeyAndVisible];

[_window
release];

//    //用Button自己的便利构造器的方式来创建对象

//    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];

//    //指定button位置和大小

//    button.frame=CGRectMake(100, 100, 100, 40);

//    //设置背景颜色

//    button.backgroundColor=[UIColor yellowColor];

//    [self.window addSubview:button];

//    //button不需要release

//    //给button设置标题

//    [button setTitle:@"抽奖" forState:UIControlStateNormal];

//    [button setTitle:@"恭喜中奖" forState:UIControlStateHighlighted];

//    //设置标题字体大小

//    button.titleLabel.font=[UIFont systemFontOfSize:20];

//    //设置圆角,(直接拿掉多余的)

//    button.layer.cornerRadius=10;

//    //设置边框

//    button.layer.borderWidth=1;

//    //点击方法 button最重要的方法

//    [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

//重新创建一个Button

UIButton *button=[UIButton
buttonWithType:UIButtonTypeSystem];

button.frame=CGRectMake(80, 300, 100, 40);

//    button.backgroundColor=[UIColor yellowColor];

[self.window
addSubview:button];

//    [button setTitle:@"确认" forState:UIControlStateNormal];

//    button.layer.borderWidth=1;

//    button.layer.cornerRadius=10;

[button addTarget:self
action:@selector(changePic:)
forControlEvents:UIControlEventTouchUpInside];

//设置一个tag值

button.tag=1000;

//给button设置背景图片

[button setBackgroundImage:[UIImage
imageNamed:@"checked.png"]
forState:UIControlStateNormal];

UIButton *button1=[UIButton
buttonWithType:UIButtonTypeCustom];

button1.frame=CGRectMake(220, 300, 100, 40);

//    button1.backgroundColor=[UIColor redColor];

[self.window
addSubview:button1];

[button1 setTitle:@"注册"
forState:UIControlStateNormal];

//    button1.layer.borderWidth=1;

button1.layer.cornerRadius=10;

[button1 addTarget:self
action:@selector(changeImage:)
forControlEvents:UIControlEventTouchUpInside];

button1.tag=1001;

self.isSelected =YES;

//如果想使用setImage设置图片的话,button的类型要调整成custom,setImage方法不会把图片方达成按钮大小

[button1 setImage:[UIImage
imageNamed:@"BtnOff.png"]
forState:UIControlStateNormal];

self.isClick=YES;

return
YES;

}

-(void)changePic:(UIButton *)button{

if (self.isSelected) {

[button setBackgroundImage:[UIImage
imageNamed:@"check.png"]
forState:UIControlStateNormal];

}else{

[button setBackgroundImage:[UIImage
imageNamed:@"checked.png"]
forState:UIControlStateNormal];

}

//把当前的状态进行调整

self.isSelected =!self.isSelected;

}

-(void)changeImage:(UIButton *)button1{

if (self.isClick ) {

[button1 setImage:[UIImage
imageNamed:@"BtnOn.png"]
forState:UIControlStateNormal];

}else{

[button1 setImage:[UIImage
imageNamed:@"BtnOff.png"]
forState:UIControlStateNormal];

}self.isClick ^=1;

}

-(void)click:(UIButton *)button{

//    UIButton *but=(UIButton *)[self.window viewWithTag:1000];

//    // 判断当前按钮的标题

//    //currentTitle获取当前按钮的标题

//    NSLog(@"%@",but.currentTitle);

//    if ([button.currentTitle isEqualToString:@"确认"]) {

//        [but setTitle:@"取消" forState:UIControlStateNormal];

//    }else{

//        [but setTitle:@"确认" forState:UIControlStateNormal];

//    }

//
按钮的点击方法会传过来一个相应类型的button,谁触发了这个点击方法,相应的button就是哪个对象

//    NSLog(@"%ld",button.tag);

if ([button.currentTitle
isEqualToString:@"确认"]) {

[button setTitle:@"取消"
forState:UIControlStateNormal];

}else{

[button setTitle:@"确认"
forState:UIControlStateNormal];

}

}

;

//-(void)click:(UIButton *)button{

//    NSLog(@"d测试按钮的点击方法");

//}

- (void)applicationWillResignActive:(UIApplication *)application {

// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application
and it begins the transition to the background state.

// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}

- (void)applicationDidEnterBackground:(UIApplication *)application {

// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}

- (void)applicationWillEnterForeground:(UIApplication *)application {

// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}

- (void)applicationDidBecomeActive:(UIApplication *)application {

// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}

- (void)applicationWillTerminate:(UIApplication *)application {

// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}

@end

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-06 09:56:18

iOS UI02_UIButton的相关文章

iOS -- SKSpriteNode类

SKSpriteNode类 继承自 SKNode:UIResponder:NSObject 符合 NSCoding(SKNode)NSCopying(SKNode)NSObject(NSObject) 框架  /System/Library/Frameworks/SpriteKit.framework 可用性 可用于iOS 7.0或者更晚的版本 声明于 SKSpriteNode.h 参考指南 Sprite Kit Progamming Guide 概览 重要提示:这是一个初步的API或者开发技术

使用fruitstrap实现命令行将IPA包安装到iOS设备上

Requirements Mac OS X. Tested on Snow Leopard only. You need to have a valid iPhone development certificate installed. Xcode must be installed, along with the SDK for your iOS version. Usage fruitstrap [-d] -b <app> [device_id] Optional -d flag laun

iOS -- SKScene类

SKScene类 继承自 SKEffectNode:SKNode:UIResponder:NSObject 符合 NSCoding(SKNode)NSCopying(SKNode)NSObject(NSObject) 框架  /System/Library/Frameworks/SpriteKit.framework 可用性 可用于iOS 7.0或者更晚的版本 声明于 SKScene.h 参考指南 Sprite Kit Progamming Guide 概览 重要提示:这是一个初步的API或者开

iOS -- SKPhysicsWorld类

SKPhysicsWorld类 继承自 NSObject 符合 NSCodingNSObject(NSObject) 框架  /System/Library/Frameworks/SpriteKit.framework 可用性 可用于iOS 7.0或者更晚的版本 声明于 SKPhysicsWorld.h 参考指南 Sprite Kit Progamming Guide 概览 重要提示:这是一个初步的API或者开发技术文档.虽然已经审阅了本文档的技术准确性,但是它不是最终的版本.本机密信息仅适用于

iOS证书说明和发布

1.首先通过钥匙串访问——证书助理——从证书颁发机构请求证书——填写证书信息(邮箱,常用名称,存储到磁盘)——存储为(自定义名称.certSigningReuqest,简称CSR文件,只是为了提交到苹果开发者账号中,然后就没用了)到本地 2.苹果开发者账号中,创建证书(Development和Production)——上传CSR文件——下载证书运行 ( xxx.cer文件) 注意:只有在当前电脑中生成本地生成证书,上传到苹果开发账号,然后下载cer文件运行后,钥匙串中才有证书以及对应的秘钥 如果

iOS开发——项目实战总结&amp;UITableView性能优化与卡顿问题

UITableView性能优化与卡顿问题 1.最常用的就是cell的重用, 注册重用标识符 如果不重用cell时,每当一个cell显示到屏幕上时,就会重新创建一个新的cell 如果有很多数据的时候,就会堆积很多cell.如果重用cell,为cell创建一个ID 每当需要显示cell 的时候,都会先去缓冲池中寻找可循环利用的cell,如果没有再重新创建cell 2.避免cell的重新布局 cell的布局填充等操作 比较耗时,一般创建时就布局好 如可以将cell单独放到一个自定义类,初始化时就布局好

解决ios下的微信打开的页面背景音乐无法自动播放

后面的项目发现,还有两个坑,需要注意下: ·本文的解决方案的核心是利用了 微信/易信 在ready的时候会有个 WeixinJSBridgeReady/YixinJSBridgeReady事件,通过监听这个事件来触发的.那有个坑就是 如果微信已经ready了,但还没执行到你监听这个ready事件的代码,那么你的监听是没用的,所以最理想的情况是,监听的js放在head前面(放在css外链之前),确保最新执行,切记!切记!. ·另一个坑就是,本文的解决方案只适合一开始就播放的背景音乐.如果你是做那种

iOS程序执行顺序和UIViewController 的生命周期(整理)

说明:此文是自己的总结笔记,主要参考: iOS程序的启动执行顺序 AppDelegate 及 UIViewController 的生命周期 UIView的生命周期 言叶之庭.jpeg 一. iOS程序的启动执行顺序 程序启动顺序图 iOS启动原理图.png 具体执行流程 程序入口进入main函数,设置AppDelegate称为函数的代理 程序完成加载[AppDelegate application:didFinishLaunchingWithOptions:] 创建window窗口 程序被激活[

iOS库--.a与.framework

一.什么是库? 库是共享程序代码的方式,一般分为静态库和动态库. 二.静态库与动态库的区别? 静态库:链接时完整地拷贝至可执行文件中,被多次使用就有多份冗余拷贝. 动态库:链接时不复制,程序运行时由系统动态加载到内存,供程序调用,系统只加载一次,多个程序共用,节省内存. 三.iOS里静态库形式? .a和.framework 四.iOS里动态库形式? .dylib和.framework 五.framework为什么既是静态库又是动态库? 系统的.framework是动态库,我们自己建立的.fram