IOS_UI_UIButton及其指令

#import <UIKit/UIKit.h>


@interface AppDelegate : UIResponder <UIApplicationDelegate>


@property (strong, nonatomic) UIWindow *window;



@end

#import "AppDelegate.h"

#import "MainViewController.h"

@interface AppDelegate ()


@end


@implementation AppDelegate

- (void)dealloc

{

    [_window release];

    [super dealloc];

}

//应用程序加载完毕//command+shift+h返回 command+shift+hh退出

- (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];

    

     MainViewController *mainVC = [[MainViewController alloc]init];

    self.window.rootViewController = mainVC;

    [mainVC release];

    NSLog(@"应用程序加载完毕");

    return YES;

}


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

    NSLog(@"将要取消激活状态");

    //使用这个方法暂停正在进行的任务,停止计时器,减缓帧率,游戏要使用这个方法暂停游戏

    // 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 {

    NSLog(@"已经进入后台");

    //使用这个方法释放资源,保存用户数据,废弃计时器,保存足够多得应用程序数据,防止在后台被退出或者在重新进入前台的时候快速恢复状态

    // 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 {

    NSLog(@"将要进入前台");

    // 撤销一些进入后台前的改变

    // 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 {

    NSLog(@"已经转为激活状态");

    //重新启动被暂停的任务,如果应用程序之前在后台,可以选择刷新用户界面

    // 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 {

    NSLog(@"将要退出/结束");

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

}


@end

#import <UIKit/UIKit.h>


@interface MainViewController : UIViewController


@end


#import "MainViewController.h"


@interface MainViewController ()


@end


@implementation MainViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 335, 50)];

    label.backgroundColor = [UIColor yellowColor];

    [self.view addSubview:label];

    [label release];

    

    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];

    button.frame = CGRectMake(20, 120, 335, 50);

    [button setTitle:@"click" forState:UIControlStateNormal];

    button.backgroundColor = [UIColor yellowColor];

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

    [self.view addSubview:button];

    //将一个试图排除在响应者链之外,即:让一个视图不响应用户交互

    // ios系统中有两个视图默认是关闭的,UILabel和UIImageView

    button.userInteractionEnabled = YES;

  }

- (void)buttonAction:(UIButton *)button

{

    NSLog(@"点击");

    button.backgroundColor = [UIColor redColor];

}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

    NSLog(@"触摸开始");

    self.view.backgroundColor = [UIColor redColor];

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

{

    NSLog(@"触摸移动");

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

{

    NSLog(@"触摸结束");

}

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event

{

    NSLog(@"摇一摇开始");

}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event

{

    NSLog(@"摇一摇结束");

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值