Open judaco opened 7 years ago
//
// ViewController.m
// Button
//
// Created by hackeru on 05/04/2017.
// Copyright © 2017 juda. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
{
UIButton * btn;
}
- (void)viewDidLoad {
[super viewDidLoad];
btn = [UIButton buttonWithType:UIButtonTypeSystem];//system the basic button in iPhone
btn.frame = CGRectMake(100, 70, 100, 40);
[btn setTitle:@"click me" forState:UIControlStateNormal];
[btn setTitle:@"I'm clicked" forState:UIControlStateHighlighted];//if i want to change the written on the button
//1.my target id is self. 2.if the button clicked must get a parm, we must add the ":" after the name of the method
[btn addTarget:self action:NSSelectorFromString(@"buttonTouchDown:") forControlEvents:UIControlEventTouchDown];
[btn addTarget:self action:NSSelectorFromString(@"buttonTouchUp:") forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
-(void)buttonTouchDown: (UIButton *) sender {
NSLog(@"touch");
}
-(void)buttonTouchUp: (UIButton *) sender {
NSLog(@"up");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
//
// ViewController.m
// CounterPlus
//
// Created by hackeru on 05/04/2017.
// Copyright © 2017 juda. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
{
UIButton * btn;
UILabel * label;
int counter;
}
- (void)viewDidLoad {
[super viewDidLoad];
//label = [[UILabel alloc] initWithFrame:CGRectMake((self.view.frame.size.width-100)/2, 100, 100, 30)];
label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
label.center = CGPointMake(self.view.center.x, 150);
label.text = [[NSString alloc] initWithFormat:@"%i", counter];
label.textAlignment = NSTextAlignmentCenter;
label.backgroundColor = [UIColor yellowColor];
[self.view addSubview:label];
btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(label.frame.origin.x, label.frame.origin.y + label.frame.size.height + 5, label.frame.size.width, label.frame.size.height);
[btn setTitle:@"increase" forState:UIControlStateNormal];
//[btn addTarget:self action:NSSelectorFromString(@"buttonTouchDown:") forControlEvents:UIControlEventTouchDown];
[btn addTarget: self action: NSSelectorFromString(@"btnIncrease:") forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview: btn];
}
-(void)btnIncrease: (UIButton *) sender {
counter++;
label.text = [[NSString alloc] initWithFormat:@"%i", counter];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
//
// ViewController.m
// Button Image
//
// Created by hackeru on 05/04/2017.
// Copyright © 2017 juda. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
{
UIButton * button;
}
- (void)viewDidLoad {
[super viewDidLoad];
UIImage * img1 = [UIImage imageNamed:@"img1"];
UIImage * img2 = [UIImage imageNamed:@"img2"];
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 100, 100);
button.center = self.view.center;
[button setTitle:@"click me" forState:UIControlStateNormal];
[button setTitle:@"clicked" forState:UIControlStateHighlighted];
[button setTitleColor: [UIColor greenColor] forState:UIControlStateNormal];
[button setBackgroundImage:img1 forState:UIControlStateNormal];
[button setBackgroundImage:img2 forState:UIControlStateHighlighted];
[self.view addSubview:button];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end