ios_开发常用代码

2016-11-29  本文已影响10人  Dante丶

tabview 常用代码

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
      return 3;
    }
    - (NSInteger)tableView:(UITableView *)tableView
     numberOfRowsInSection:(NSInteger)section {
      return 5;
    }
    - (UITableViewCell *)tableView:(UITableView *)tableView
             cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@""];
      if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault)
                                      reuseIdentifier:@""];
      }
      cell.textLabel.text = @"红包";
      return cell;
    }

tab cell分割线

    Tab.separatorInset=UIEdgeInsetsZero;
    Tab.layoutMargins=UIEdgeInsetsZero;
    cell?.layoutMargins=UIEdgeInsetsZero;

设置tab分割线可见

//  _redTab.separatorStyle = NO;

判断字符串是否包含

NSString *str1 = @"abcd";
        
        NSString *str = @"a";
        
        //在str1这个字符串中搜索\n,判断有没有
        
        if([str1 rangeOfString:str].location != NSNotFound) {
            
            NSLog(@"这个字符串中有a");
            
        }

去掉mas_makeConstraints、mas_left、mas_equalTo等这种类型的前面的mas_

    //加入这个宏,可以省略所有 mas_ (除了mas_equalTo)
    #define MAS_SHORTHAND
    
    //加入这个宏,那么mas_equalTo就和equalTo一样的了
    #define MAS_SHORTHAND_GLOBALS
    
    //上面的两个宏一定要在这句之前
    #import "Masonry.h"
    
    //这样写了之后,代码就变成这样了
        [控件 makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.left).offset(50);
            make.right.equalTo(self.view.right).offset(-50);
            make.top.equalTo(self.view.top).offset(50);
            make.bottom.equalTo(self.view.bottom).offset(-50);
        }];

Masonry动画效果

       mybtn1 *btn1=[[mybtn1 alloc]init];
    btn1.backgroundColor=[UIColor blackColor];
    btn1.tag=1;
    [self.view addSubview:btn1];
    
    [btn1 mas_updateConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(CGSizeMake(100, 100));
        make.centerX.equalTo(self.view.centerX);
        make.centerY.equalTo(self.view.centerY);
    }];
    // 告诉self.headerView约束需要更新
    [btn1 setNeedsUpdateConstraints];
    // 调用此方法告诉self.headerView检测是否需要更新约束,若需要则更新,下面添加动画效果才起作用
    [btn1 updateConstraintsIfNeeded];
    
    [UIView animateWithDuration:0.3 animations:^{
        [btn1 layoutIfNeeded];
    }];

xcode disk image 路径

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport

判断字符串是否包含

    在iOS8以后,还可以用下面的方法来判断是否包含某字符串:

    NSString *women = @"Hey you are bitch ?";
    
    if ([women containsString:@"bitch"]) {
    
    NSLog(@"women 包含 bitch");
    
    } else {
    
    NSLog(@"women 不存在 bitch");
    
    }

    NSString *string = @"hello,fucking,you,bitch";
    
    //字条串是否包含有某字符串
    
    if ([string rangeOfString:@"fucking"].location == NSNotFound) {
    
    NSLog(@"string 不存在 fucking");
    
    } else {
    
    NSLog(@"string 包含 fucking");
    
    }
    
    //字条串开始包含有某字符串
    
    if ([string hasPrefix:@"hello"]) {
    
    NSLog(@"string 包含 hello");
    
    } else {
    
    NSLog(@"string 不存在 hello");
    
    }
    
    //字符串末尾有某字符串;
    
    if ([string hasSuffix:@"bitch"]) {
    
    NSLog(@"string 包含 bitch");
    
    } else {
    
    NSLog(@"string 不存在 bitch");
    
    }

js代码片段

     JSContext *context = [webView
          valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
      context[@"clickOnIos"] = ^() {
        dispatch_async(dispatch_get_main_queue(), ^{
          if (_typeNum == 3) {
            [self.delagate backToBankManage:YES];
            [self.navigationController popViewControllerAnimated:YES];
          } else {
            [self.navigationController popViewControllerAnimated:YES];
          }
    
        });
      };

这是系统消息webview_url

     NSString *dateStr=[[NSString alloc]init];
     NSDateFormatter *dateformat = [[NSDateFormatter alloc] init];
        [dateformat setDateFormat:@"yyyy-MM-dd-HH"];
        NSString *datestring = [dateformat stringFromDate:[NSDate date]];
        //    NSLog(@"datestring:%@",datestring);
        //    NSLog(@"user  id:%@",AppDelegateInstance.userInfo.userId);
        dateStr = [[NSString stringWithFormat:@"%@%@%@",
                                              AppDelegateInstance.userInfo.userId,
                                              datestring, MD5key] md5];
    //url_链接
     [webView
          loadRequest:
              [NSURLRequest
                  requestWithURL:
                      [NSURL
                          URLWithString:
                              [NSString stringWithFormat:
                                            @"%@%@&id=%@&key=%@", Baseurl,
                                            @"/wechat/find/message?showin=app",
                                            AppDelegateInstance.userInfo.userId,
                                            dateStr]]]];

随机游客 _客服系统

    //    NSDictionary *parameters = @{
    //      @"user" : @{
    //        @"nick_name" : [NSString
    //            stringWithFormat:@"%@%u", @"iOS_游客", arc4random() % 10000000],
    //        @"cellphone" : [NSString stringWithFormat:@"%@", @"15700000000"],
    //        @"email" : @"hzed@hzed.com",
    //        @"description" : @"iOS",
    //        @"sdk_token" :
    //            [NSString stringWithFormat:@"%u", arc4random() % 10000000]
    //      }
    //    };
    //
    //    [UdeskManager createCustomerWithCustomerInfo:parameters];
    //    UdeskSDKManager *chat =
    //        [[UdeskSDKManager alloc] initWithSDKStyle:[UdeskSDKStyle defaultStyle]];
    //    [chat pushUdeskViewControllerWithType:UdeskIM
    //                           viewController:self
    //                               completion:nil];

JavaScript 调用oc

    #import <JavaScriptCore/JavaScriptCore.h>
        - (void)webViewDidFinishLoad:(UIWebView *)webView {
      [SVProgressHUD dismiss];
      JSContext *context = [webView
          valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
      context[@"invitation_Reward"] = ^() {
        dispatch_async(dispatch_get_main_queue(), ^{
          //       邀请奖励
          InviteRewardsViewController *invitationView =
              [[InviteRewardsViewController alloc] init];
          invitationView.hidesBottomBarWhenPushed = YES;
          invitationView.shareUrl = [NSString
              stringWithFormat:@"%@", AppDelegateInstance.userInfo.spreadLink];
          invitationView.recommend = _recommand;
          [self.navigationController pushViewController:invitationView
                                               animated:YES];
        });
    
      };
    }
上一篇下一篇

猜你喜欢

热点阅读