Xcode-程序开发设计-01UIKit 框架

CGRect中的前缀:CoreGraphics.frameworks
UIView中的前缀:User InterFace 属于UIKit的框架
NS前缀,NS是NextStep

对象方法:辞去第1响应者-  [self.num1 resingFistResponder] [self.view endEditing:YES] //参数是表示是否强行退出  :将退出当前view的子控件叫出的键盘

* 将独有的方法或属性放到私有扩展(类扩展)中 不要放到.h的声明中 保证封装性。

 

1.IBAction:
1> 能保证方法可以连线
2> 相当于void

2.IBOutlet:
1> 能保证属性可以连线

3.常见错误
setValue:forUndefinedKey:]: this class is not key value coding
错误原因是:连线出问题了

4.Xcode5开始的一些建议
把用于连线的一些方法和属性声明在.m文件的类扩展中

5.frame\center\bounds 常用属性
1> CGRect frame:能修改位置和尺寸
2>CGPoint center:能修改位置
3>CGRect bounds:能修改尺寸(x\y一般都是0)

 代码方式添加按钮 并做监听

//设置按钮点后调用的方法 传入了参数 可以识别是哪个按钮做的点击(方法名:printLine:)注意冒号
- (void)printLine:(UIButton *)button
{
    NSLog(@"-------%@",button);
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // 创建指定类型的按钮 不用设置文字/颜色等信息就可以显示,是系统的样式 默认位置 0, 0
    UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeContactAdd];
    [self.view addSubview:addBtn];
    //addBtn.center = CGPointMake(80, 80);
    CGPoint center = addBtn.center;
    center.x = 80;
    center.y = 80;
    addBtn.center = center;
    
    // 不使用拖线来实现按钮的监听
    // id 谁来监听   SEL指向方法的指针 把方法封闭成一个SEL
    //[addBtn addTarget:<#(nullable id)#> action:<#(nonnull SEL)#> forControlEvents:<#(UIControlEvents)#>]
    [addBtn addTarget:self action:@selector(printLine:) forControlEvents:UIControlEventTouchUpInside];
    
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDelay:1];
    
    // 1.创建按钮 并添加到view中
    UIButton *iconButton = [[UIButton alloc] init];
    [self.view addSubview:iconButton];
    
    // 2.设置Title文字及其颜色
    [iconButton setTitle:@"来点我" forState:UIControlStateNormal];
    [iconButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    
    
    [iconButton setTitle:@"摸我干啥" forState:UIControlStateHighlighted];
    [iconButton setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];
    
    // 3.设置背影图片 非setImage(上方图片) png图片不用加扩展名
    UIImage *btn_01 = [UIImage imageNamed:@"btn_01"];
    [iconButton setBackgroundImage:btn_01 forState:UIControlStateNormal];
    
    [iconButton setBackgroundImage:[UIImage imageNamed:@"btn_02"] forState:UIControlStateHighlighted];
    
    // 4.使用frame设置按钮的大小及位置
    iconButton.frame =CGRectMake(100, 100, 100, 100);
    [iconButton addTarget:self action:@selector(printLine:) forControlEvents:UIControlEventTouchUpInside];
    
    [UIView commitAnimations];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 transform(改变、使...变形)的使用 ..位置、尺寸、旋转角度

transform属性默认是在初始状态的基础上进行改变状态的(平稳.....等) 是相对于最初属性的

 

- (IBAction)test
{
    // 根据tag找到控件
    //UIButton *iconButton = [self.view viewWithTag:10];
    // 下边的transform属性是根据初始值来操作的 AffineTransform(几何改变)
    
    // 创建平移变化
    //iconButton.transform = CGAffineTransformMakeTranslation(0, -100);
    
    // 创建缩放变化 根据比例  Scale(比例)
    //iconButton.transform = CGAffineTransformMakeScale(1.2, 1.2);
    
    // 创建旋转变化 Rotate(旋转) 非角度制:45/90/180 是弧度制 pi是180度 二分之pi是90度
    //iconButton.transform = CGAffineTransformMakeRotation(1.0);
    
    //下边的依据是对象当前状态为基础
    //iconButton.transform = CGAffineTransformTranslate(iconButton.transform, 0, -10);
    
    //iconButton.transform = CGAffineTransformScale(iconButton.transform, 1.1, 1.1);
    
    //iconButton.transform = CGAffineTransformRotate(iconButton.transform, M_PI_2);
    
}

 

posted @ 2015-12-29 09:11  呆而肥  阅读(935)  评论(0编辑  收藏  举报