XCode的使用心得

XCode的使用心得

没有提示。esc 按一下,就有提示

ctrl + cmd + 左右 ,可以切换头文件 和点m文件

//
//  ViewController.m
//  Transform属性的使用
//
//  Created by lujun on 2021/5/18.
//

#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *imgIcon;
@property(nonatomic,assign)int delta;
@end
@implementation ViewController
- (IBAction)rotate:(id)sender {
    // 正数是顺时针的旋转
    //负数时逆时针旋转
    self.imgIcon.transform = CGAffineTransformRotate(self.imgIcon.transform, -M_PI_4);
}
- (IBAction)zoomBigSmall:(id)sender {
    [UIView animateWithDuration:1.5 animations:^{
        self.imgIcon.transform = CGAffineTransformScale(self.imgIcon.transform, 1.2, 1.2);
     }];
}
- (IBAction)move:(id)sender {
//    self.delta -= 20;
//    NSLog(@"%d",self.delta);
//    self.imgIcon.transform = CGAffineTransformMakeTranslation(0, self.delta);
    //基于Translate是基于transform参数做的形变,实际效果就是一个累加的位移效果
    self.imgIcon.transform = CGAffineTransformTranslate(self.imgIcon.transform, 0, -20);
}
- (void)viewDidLoad{
}
@end
//
//  ViewController.m
//  纯代码创建按钮的演练
//
//  Created by lujun on 2021/5/18.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
     //一定不要忘记调用父类的实现方法
    UIButton *btn = [[UIButton alloc] init];
    btn.frame =CGRectMake(20, 20, 100, 100);
   // btn.backgroundColor = [UIColor redColor];
    [btn setTitle:@"点我" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    UIImage *image = [UIImage imageNamed:@"btn_01"];
    [btn setBackgroundImage:image forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"btn_02"] forState:UIControlStateHighlighted];
    [btn setTitle:@"摸我干啥" forState:UIControlStateHighlighted];
    [btn setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];
    [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
     [self.view addSubview:btn];
}
-(void)click:(UIButton *) btn{
    NSLog(@"asda");
}
@end

//
//  ViewController.m
//  02-transform属性的介绍
//
//  Created by 鲁军 on 2021/1/30.
//

#import "ViewController.h"
@interface ViewController ()
- (IBAction)move;
- (IBAction)rotate;
- (IBAction)scale;
@property (weak, nonatomic) IBOutlet UIButton *btnIcon;
- (IBAction)clear;
@property (weak, nonatomic) IBOutlet UITextField *txt1;
- (IBAction)test;
@end
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
}
- (IBAction)scale {
    // self.btnIcon.transform = CGAffineTransformMakeScale(0.5,0.5);
     self.btnIcon.transform = CGAffineTransformScale(self.btnIcon.transform, 1.5, 1.5);
}
- (IBAction)rotate {
  //  self.btnIcon.transform = CGAffineTransformMakeRotation(-M_PI_4);
   // self.btnIcon.transform = CGAffineTransformRotate(self.btnIcon.transform, -M_PI_4);
    [UIView animateWithDuration:2.5 animations:^{
        self.btnIcon.transform = CGAffineTransformRotate(self.btnIcon.transform, -M_PI_4);
        self.btnIcon.transform =  CGAffineTransformTranslate(self.btnIcon.transform, 0, 50);
        self.btnIcon.transform = CGAffineTransformScale(self.btnIcon.transform, 1.5, 1.5);
    }];
}
- (IBAction)move {
    // 下面这句话的意思是 告诉控件。平移到距离原始位置-50 的位置
     //self.btnIcon.transform = CGAffineTransformMakeTranslation(0, -50);
    // 基于 一个旧的值 在进行平移
    // 基于现有的一个值。再进行平移
  self.btnIcon.transform =  CGAffineTransformTranslate(self.btnIcon.transform, 0, 50);
}
- (IBAction)clear {
    self.btnIcon.transform = CGAffineTransformIdentity;
}
- (IBAction)test {
//    for (UIView *view in self.view.subviews) {
//        view.backgroundColor=[UIColor redColor];
//    }
  //self.txt1.superview.backgroundColor=[UIColor yellowColor];
//
//    UITextField *txt = (UITextField *)[self.view viewWithTag:110];
//    txt.text = @"大军";
 while(self.view.subviews.firstObject){
        [self.view.subviews.firstObject
         removeFromSuperview];
     }
}
@end

//
//  ViewController.m
//  04-图片浏览器
//
//  Created by lujun on 2021/5/18.
//

#import "ViewController.h"

@interface ViewController ()
@property(nonatomic,strong)UILabel *noLabel;
@property(nonatomic,strong)UIImageView *icon;
@property(nonatomic,strong)UILabel *descLabel;
@property(nonatomic,strong)UIButton *leftButton;
@property(nonatomic,strong)UIButton *rightButton;
@property(nonatomic,assign)int index;

@property(nonatomic,strong)NSArray *imageList;
@end

@implementation ViewController

- (NSArray *)imageList{
    if(_imageList==nil){
        NSDictionary *dict1 = @{@"name":@"1",@"desc":@"表情"};
        NSDictionary *dict2 = @{@"name":@"2",@"desc":@"病例"};
        NSDictionary *dict3 = @{@"name":@"3",@"desc":@"吃饭"};
        NSDictionary *dict4 = @{@"name":@"4",@"desc":@"蛋疼"};
        NSDictionary *dict5 = @{@"name":@"5",@"desc":@"王八"};
        _imageList = @[dict1,dict2,dict3,dict4,dict5];
        
    }
    
    return _imageList;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //NSLog(@"%@",NSStringFromCGRect(self.view.frame));
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, 414, 140)];
  //  label.text = @"1/5";
    label.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:label];
    self.noLabel = label;
    //图片视图
    CGFloat imageW = 200,imageH = 200,imageY = 180;
    CGFloat imageX = (414-imageW)/2;
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(imageX, imageY, imageW, imageH)];
    
    //UIImage *image = [UIImage imageNamed:@"0"];
    
  //  imageView.image = image;
    
    [self.view addSubview:imageView];
    self.icon = imageView;
    //imageView 是相框,容器,盛放图片
//    image 是 从磁盘加载的一张图片
    //两者不一样。有本质区别
    //NSLog(@"%@",NSStringFromCGRect(imageView.frame));
    //描述标签
    UILabel *descLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 400, 414, 140)];
    //descLabel.text = @"弱爆了,神马表情";
    descLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:descLabel];
    self.descLabel = descLabel;
    
    //左边按钮
    UIButton *leftButton = [[UIButton alloc] init];
   // leftButton.backgroundColor = [UIColor redColor];
    //设置按钮的背景图片
    [leftButton setBackgroundImage:[UIImage imageNamed:@"left_normal"] forState:UIControlStateNormal];
    [leftButton setBackgroundImage:[UIImage imageNamed:@"left_highlighted"] forState:UIControlStateHighlighted];
   // NSLog(@"%f",self.icon.frame.origin.x);
    //先虚拟化一个位置,再 通过center 定位到指定位置。先把大小创建出来
    leftButton.frame=CGRectMake(0, 0, 40, 40);
    leftButton.center = CGPointMake(self.icon.frame.origin.x/2, self.icon.center.y);
    [self.view addSubview:leftButton];
    self.leftButton = leftButton;
    
    //右边按钮
    UIButton *rightButton = [[UIButton alloc] init];
    //rightButton.backgroundColor = [UIColor redColor];
    //right_normal
    //right_highlighted
    //设置按钮的背景图片
    [rightButton setBackgroundImage:[UIImage imageNamed:@"right_normal"] forState:UIControlStateNormal];
    [rightButton setBackgroundImage:[UIImage imageNamed:@"right_highlighted"] forState:UIControlStateHighlighted];
    //NSLog(@"%f",self.icon.frame.origin.x);
    //先虚拟化一个位置,再 通过center 定位到指定位置。先把大小创建出来
    rightButton.frame=CGRectMake(0, 0, 40, 40);
    rightButton.center = CGPointMake(self.view.frame.size.width - self.icon.frame.origin.x/2, self.icon.center.y);
    [self.view addSubview:rightButton];
    self.rightButton = rightButton;
    
    //点击方法的事件监听
    [leftButton addTarget:self action:@selector(leftClick) forControlEvents:UIControlEventTouchUpInside];
    [rightButton addTarget:self action:@selector(rightClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self changeImage];
    
}

#pragma mark - 修改图像数据

-(void)changeImage{
    self.noLabel.text = [NSString stringWithFormat:@"%d/%d",self.index+1,5];
    
    self.icon.image = [UIImage imageNamed:self.imageList[self.index][@"name"]];
    self.descLabel.text = self.imageList[self.index][@"desc"];
    
   /* switch (self.index) {
        case 0:
            self.icon.image = [UIImage imageNamed:@"0"];
            self.descLabel.text = @"33333";
            break;
        case 1:
            self.icon.image = [UIImage imageNamed:@"1"];
            self.descLabel.text = @"777777";
            break;
        case 2:
            self.icon.image = [UIImage imageNamed:@"2"];
            self.descLabel.text = @"345";
            break;
        case 3:
            self.icon.image = [UIImage imageNamed:@"3"];
            self.descLabel.text = @"234";
            break;
            
        case 4:
            self.icon.image = [UIImage imageNamed:@"4"];
            self.descLabel.text = @"789";
            break;
    }*/
    self.rightButton.enabled = (self.index != 4);
    self.leftButton.enabled = (self.index != 0);
}

-(void)leftClick{
    
    //NSLog(@"左");
    self.index--;
    //NSLog(@"%d",self.index);
    
    [self changeImage];
    
}

-(void)rightClick
{
    //NSLog(@"右");
    self.index++;
    
    
    [self changeImage];
    
    //NSLog(@"%d",self.index);
    //根据self.index显示的序号标签 图像 图像的描述
    
//    if(self.index==4){
//        self.rightButton.enabled = NO;
//    }
    
}
@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值