XCode的使用心得
生活随笔
收集整理的這篇文章主要介紹了
XCode的使用心得
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
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 {// 正數(shù)是順時針的旋轉(zhuǎn)//負數(shù)時逆時針旋轉(zhuǎn)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參數(shù)做的形變,實際效果就是一個累加的位移效果self.imgIcon.transform = CGAffineTransformTranslate(self.imgIcon.transform, 0, -20); } - (void)viewDidLoad{ } @end // // ViewController.m // 純代碼創(chuàng)建按鈕的演練 // // Created by lujun on 2021/5/18. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {[super viewDidLoad];//一定不要忘記調(diào)用父類的實現(xiàn)方法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);// 基于 一個舊的值 在進行平移// 基于現(xiàn)有的一個值。再進行平移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.firstObjectremoveFromSuperview];} } @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 是 從磁盤加載的一張圖片//兩者不一樣。有本質(zhì)區(qū)別//NSLog(@"%@",NSStringFromCGRect(imageView.frame));//描述標(biāo)簽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];//設(shè)置按鈕的背景圖片[leftButton setBackgroundImage:[UIImage imageNamed:@"left_normal"] forState:UIControlStateNormal];[leftButton setBackgroundImage:[UIImage imageNamed:@"left_highlighted"] forState:UIControlStateHighlighted];// NSLog(@"%f",self.icon.frame.origin.x);//先虛擬化一個位置,再 通過center 定位到指定位置。先把大小創(chuàng)建出來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//設(shè)置按鈕的背景圖片[rightButton setBackgroundImage:[UIImage imageNamed:@"right_normal"] forState:UIControlStateNormal];[rightButton setBackgroundImage:[UIImage imageNamed:@"right_highlighted"] forState:UIControlStateHighlighted];//NSLog(@"%f",self.icon.frame.origin.x);//先虛擬化一個位置,再 通過center 定位到指定位置。先把大小創(chuàng)建出來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;//點擊方法的事件監(jiān)聽[leftButton addTarget:self action:@selector(leftClick) forControlEvents:UIControlEventTouchUpInside];[rightButton addTarget:self action:@selector(rightClick) forControlEvents:UIControlEventTouchUpInside];[self changeImage];}#pragma mark - 修改圖像數(shù)據(jù)-(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);//根據(jù)self.index顯示的序號標(biāo)簽 圖像 圖像的描述// if(self.index==4){ // self.rightButton.enabled = NO; // }} @end總結(jié)
以上是生活随笔為你收集整理的XCode的使用心得的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 通过路口
- 下一篇: 用面粉和醋洗头 让你的头发黑亮又浓密