• iOS开发——常用代码块(持续添加...)


     yyt_property_strong:

      @property(nonatomic,strong) <#type#> *<#name#>;

     yyt_property_assign:

      @property(nonatomic,assign) <#type#> <#name#>;

      yyt_lineView:

        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)];

        lineView.backgroundColor = <#backgroundColor#>;

        [<#superView#> addSubview:lineView];

      yyt_bgView:

        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)];

        bgView.backgroundColor = <#backgroundColor#>;

        [<#superView#> addSubview:lineView];

        
      yyt_leftBarButton_image:

        UIButton *leftButton = [UIButton buttonWithType:(UIButtonTypeCustom)];

        self.leftButton = leftButton;

        [leftButton setImage:<#(nullable UIImage *)#> forState:(UIControlStateNormal)];

        [leftButton addTarget:self action:@selector(clickLeftButton:) forControlEvents:(UIControlEventTouchUpInside)];

        UIBarButtonItem *leftBar = [[UIBarButtonItem alloc] initWithCustomView:leftButton];

        self.navigationItem.leftBarButtonItem = leftBar;

        
      yyt_leftBarButton_title:

        UIButton *leftButton = [UIButton buttonWithType:(UIButtonTypeCustom)];

        self.leftButton = leftButton;

        leftButton.titleLabel.font = <#font#>;

        [leftButton setTitle:<#(nullable NSString *)#> forState:UIControlStateNormal];

        [leftButton setTitleColor:<#(nullable UIColor *)#> forState:UIControlStateNormal];

        [leftButton addTarget:self action:@selector(clickLeftButton:) forControlEvents:(UIControlEventTouchUpInside)];

        UIBarButtonItem *leftBar = [[UIBarButtonItem alloc] initWithCustomView:leftButton];

        self.navigationItem.leftBarButtonItem = leftBar;

        
      yyt_rightBarButton_image:

        UIButton *rightButton = [UIButton buttonWithType:(UIButtonTypeCustom)];

        self.rightButton = rightButton;

        [rightButton setImage:<#(nullable UIImage *)#> forState:(UIControlStateNormal)];

        [rightButton addTarget:self action:@selector(clickRightButton:) forControlEvents:(UIControlEventTouchUpInside)];

        UIBarButtonItem *rightBar = [[UIBarButtonItem alloc] initWithCustomView:rightButton];

        self.navigationItem.rightBarButtonItem = rightBar;

        
      yyt_rightBarButton_title:

        UIButton *rightButton = [UIButton buttonWithType:(UIButtonTypeCustom)];

        self.rightButton = rightButton;

        rightButton.titleLabel.font = <#font#>;

        [rightButton setTitle:<#(nullable NSString *)#> forState:UIControlStateNormal];

        [rightButton setTitleColor:<#(nullable UIColor *)#> forState:UIControlStateNormal];

        [rightButton addTarget:self action:@selector(clickRightButton:) forControlEvents:(UIControlEventTouchUpInside)];

        UIBarButtonItem *rightBar = [[UIBarButtonItem alloc] initWithCustomView:rightButton];

        self.navigationItem.rightBarButtonItem = rightBar;

     
      yyt_label_normal:

        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)];

        label.text = <#text#>;

        label.textColor = <#textColor#>;

        label.textAlignment = <#NSTextAlignment#>;

        label.font = <#font#>;

        [<#superView#> addSubview:label];

        
      yyt_button_image:

        UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];

        button.frame = CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>);

        [button setImage:<#(nullable UIImage *)#> forState:(UIControlStateNormal)];

        [button setImage:<#(nullable UIImage *)#> forState:(UIControlStateSelected)];

        [button addTarget:self action:@selector(<#selector#>) forControlEvents:(UIControlEventTouchUpInside)];

        [<#superView#> addSubview:loginButton];

        
      yyt_button_title:

        UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];

        button.frame = CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>);

        button.layer.cornerRadius = <#cornerRadius#>;

        button.layer.masksToBounds = YES;

        button.titleLabel.font = <#font#>;

        button.backgroundColor = <#backgroundColor#>;

        [button setTitle:<#(nullable NSString *)#> forState:(UIControlStateNormal)];

        [button setTitle:<#(nullable NSString *)#> forState:(UIControlStateSelected)];

        [button setTitleColor:<#(nullable UIColor *)#> forState:UIControlStateNormal];

        [button setTitleColor:<#(nullable UIColor *)#> forState:UIControlStateSelected];

        [button addTarget:self action:@selector(<#selector#>) forControlEvents:(UIControlEventTouchUpInside)];

        [<#superView#> addSubview:loginButton];

      yyt_textField_normal:

        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)];

        textField.textColor = <#textColor#>;

        textField.tintColor = <#tintColor#>;

        textField.font = <#font#>;

        textField.keyboardType = UIKeyboardTypeEmailAddress;

        textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:<#string#> attributes:@{NSForegroundColorAttributeName:<#textColor#>,NSFontAttributeName:<#font#>}];

        [textField addTarget:self action:@selector(<#selector#>) forControlEvents:UIControlEventEditingDidBegin];

        [textField addTarget:self action:@selector(<#selector#>) forControlEvents:UIControlEventEditingDidEnd];

        [textField addTarget:self action:@selector(<#selector#>) forControlEvents:UIControlEventEditingChanged];

        [<#superView#> addSubview:textField];

        
      yyt_textField_clearButton:

        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)];

        textField.textColor = <#textColor#>;

        textField.tintColor = <#tintColor#>;

        textField.font = <#font#>;

        textField.keyboardType = UIKeyboardTypeEmailAddress;

        textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:<#string#> attributes:@{NSForegroundColorAttributeName:<#color#>,NSFontAttributeName:<#font#>}];

        [textField addTarget:self action:@selector(<#selector#>) forControlEvents:UIControlEventEditingDidBegin];

        [textField addTarget:self action:@selector(<#selector#>) forControlEvents:UIControlEventEditingDidEnd];

        [textField addTarget:self action:@selector(<#selector#>) forControlEvents:UIControlEventEditingChanged];

        UIButton *textFieldClearButton = [textField valueForKey:@"_clearButton"];

        [textFieldClearButton setImage:<#(nullable UIImage *)#> forState:(UIControlStateNormal)];

        textField.clearButtonMode = UITextFieldViewModeWhileEditing;

        [<#superView#> addSubview:textField];

     
      yyt_addNotification:

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(<#selector#>) name:<#(nullable NSNotificationName)#> object:<#(nullable id)#>];


      yyt_postNotification:

        [[NSNotificationCenter defaultCenter] postNotificationName:<#(nonnull NSNotificationName)#> object:<#(nullable id)#>];

         

      yyt_currentTime_str:

        NSDateFormatter * formatter = [[NSDateFormatter alloc ] init];

        [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss:SSS"];

        NSString *currentTimeStr = [formatter stringFromDate:[NSDate date]];

     
      yyt_timer:

        NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:<#timeInterval#> target:self selector:@selector(<#selector#>) userInfo:nil repeats:YES];

        self.timer = timer;

        [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];


      yyt_dispatch_once

        static dispatch_once_t onceToken;

        dispatch_once(&onceToken, ^{

            

        });

        
      yyt_dispatch_main_queue:

        dispatch_async(dispatch_get_main_queue(), ^{

            

        });

        
      yyt_dispatch_global_queue:

        dispatch_async(dispatch_get_global_queue(0, 0), ^{

            

        });

        
      yyt_dispatch_after:

        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(<#timeInterval#> * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

            

        });

     
      yyt_tapGesture:

        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];

        tapGesture.numberOfTapsRequired = 1;

        [bgView addGestureRecognizer:tapGesture];

     
      yyt_handleTapGesture:

    - (void)handleTapGesture:(UITapGestureRecognizer*)sender {

        NSLog(@"handleTapGesture");

    }

        
      yyt_longPressGesture:

        UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongGesture:)];

        [bgView addGestureRecognizer:longPressGesture];

        

      yyt_handleLongGesture:

    - (void)handleLongGesture:(UILongPressGestureRecognizer*)sender {

        NSLog(@"handleLongGesture");

        CGPoint point = [sender locationInView:<#hitView#>];

        if (sender.state == UIGestureRecognizerStateBegan) {

            NSLog(@"handleLongGesture   UIGestureRecognizerStateBegan");

        } else if (sender.state == UIGestureRecognizerStateChanged) {

            NSLog(@"handleLongGesture   UIGestureRecognizerStateChanged");

        } else if (sender.state == UIGestureRecognizerStateEnded) {

            NSLog(@"handleLongGesture   UIGestureRecognizerStateEnded");

        }

    }

       
      yyt_swipeGesture:

        UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];

        swipeGesture.direction = UISwipeGestureRecognizerDirectionRight; //默认向右

        [bgView addGestureRecognizer:swipeGesture];

     
      yyt_handleSwipeGesture:

    - (void)handleSwipeGesture:(UISwipeGestureRecognizer*)sender {

        NSLog(@"handleSwipeGesture");

        UISwipeGestureRecognizer *swipe = sender;

        if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {

            //向左轻扫做的事情

            NSLog(@"handleSwipeGesture  UISwipeGestureRecognizerDirectionLeft");

        } else if (swipe.direction == UISwipeGestureRecognizerDirectionRight) {

            //向右轻扫做的事情

            NSLog(@"handleSwipeGesture  UISwipeGestureRecognizerDirectionRight");

        } else if (swipe.direction == UISwipeGestureRecognizerDirectionUp) {

            //向上轻扫做的事情

            NSLog(@"handleSwipeGesture  UISwipeGestureRecognizerDirectionUp");

        } else if (swipe.direction == UISwipeGestureRecognizerDirectionDown) {

            //向下轻扫做的事情

            NSLog(@"handleSwipeGesture  UISwipeGestureRecognizerDirectionDown");

        }

    }

       


      yyt_pinchGesture:

        UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(handlePinchGesture:)];

        [<#superView#> addGestureRecognizer:pinchGesture];

     
      yyt_handlePinchGesture:

    - (void)handlePinchGesture:(UIPinchGestureRecognizer*)sender {

        NSLog(@"handlePinchGesture");

        if (sender.state == UIGestureRecognizerStateBegan) {

            NSLog(@"handlePinchGesture  UIGestureRecognizerStateBegan");

        } else if (sender.state == UIGestureRecognizerStateChanged) {

            NSLog(@"handlePinchGesture  UIGestureRecognizerStateChanged");

            self.bgView.transform = CGAffineTransformMakeScale(sender.scale, sender.scale);

        } else if (sender.state == UIGestureRecognizerStateEnded) {

            NSLog(@"handlePinchGesture  UIGestureRecognizerStateEnded");

            [UIView animateWithDuration:0.5 animations:^{

                self.bgView.transform = CGAffineTransformIdentity;//取消一切形变

            }];

        }

    }

        


      yyt_panGesture:

        UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];

        [<#superView#> addGestureRecognizer:panGesture];


      yyt_handlePanGesture:

    - (void)handlePanGesture:(UIPanGestureRecognizer*)sender {

        NSLog(@"handlePanGesture");

        if (sender.state == UIGestureRecognizerStateBegan) {

            NSLog(@"handlePanGesture    UIGestureRecognizerStateBegan");

        } else if (sender.state == UIGestureRecognizerStateChanged) {

            NSLog(@"handlePanGesture    UIGestureRecognizerStateChanged");

        } else if (sender.state == UIGestureRecognizerStateEnded) {

            NSLog(@"handlePanGesture    UIGestureRecognizerStateEnded");

        }

    }


      

  • 相关阅读:
    四十四 常用内建模块 struct
    四十三 常用内建模块 base64
    Django Haystack 全文检索与关键词高亮
    python实现简单tftp(基于udp)
    多线程socket UDP收发数据
    Python 线程复习
    python 进程复习
    python pdb 调试
    Linux 复习
    Django 博客
  • 原文地址:https://www.cnblogs.com/yyt-hehe-yyt/p/14085549.html
Copyright © 2020-2023  润新知