//
// AppDelegate.m
// UI02_Button
//
// Created by lanou3g on 17/8/4.
// Copyright © 2017年 lanou3g. All rights reserved.
//
#import "AppDelegate.h"
#import "RootViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (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 whiteColor];
[self.window makeKeyAndVisible];
RootViewController *rootViewController = [[RootViewController alloc] init];
self.window.rootViewController = rootViewController;
return YES;
}
- (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
//
// RootViewController.m
// UI02_Button
//
// Created by lanou3g on 17/8/4.
// Copyright © 2017年 lanou3g. All rights reserved.
//
#import "RootViewController.h"
@interface RootViewController ()
@property (nonatomic, assign) NSInteger count;
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(100, 100, 100, 100);
button.backgroundColor = [UIColor redColor];
//设置button某状态的标题
[button setTitle:@"你好" forState:UIControlStateNormal];
[button setTitle:@"我不好" forState:UIControlStateHighlighted];
[button setTitle:@"被选中" forState:UIControlStateSelected];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
//
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(100, 350, 100, 100);
button1.backgroundColor = [UIColor orangeColor];
// [button1 setTitle:@"点呗" forState:UIControlStateNormal];
[button1 setBackgroundImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal];
[button1 addTarget:self action:@selector(button1Action:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button1];
}
- (void)button1Action:(UIButton *)button1 {
self.count += 1;
CGFloat x = button1.isSelected ? 100 : 200;
button1.selected = !button1.isSelected;
button1.frame = CGRectMake(x, 350, 100, 100);
NSLog(@"点击成功");
if (10 == self.count) {
[button1 setTitle:@"换个方式" forState:UIControlStateNormal];
self.count = 0;
}else {
[button1 setTitle:@"点呗" forState:UIControlStateNormal];
}
}
- (void)buttonAction:(UIButton *)button {
CGFloat y = button.isSelected ? 100:200;
button.selected = !button.isSelected;
button.frame = CGRectMake(100, y, 100, 100);
NSLog(@"别戳我");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end