1. 程式人生 > >iOS開發中一些常用的方法

iOS開發中一些常用的方法

1.壓縮圖片
#pragma mark 處理圖片
- (void)useImage:(UIImage *)image
{
    NSLog(@"with-----%f heught-----%f",image.size.width,image.size.height);
    
    float  scales = image.size.height / image.size.width; //圖片比例
    NSLog(@"圖片比例:%f",scales);
    
    UIImage * normalImg;
    
    if (image.size.width >300 || image.size.height > 300) {
        
        if (scales > 1) {
            
            normalImg = [self imageWithImageSimple:image scaledToSize:CGSizeMake(300 / scales, 300)];
            
        }else {
            
            normalImg = [self imageWithImageSimple:image scaledToSize:CGSizeMake(300 ,300 * scales)];
        }
    }
    else {
        
        normalImg = image;
    }
    
    NSLog(@"第一次處理後:with-----%f height-----%f",normalImg.size.width, normalImg.size.height);
    CGSize newSize = CGSizeMake(normalImg.size.width, normalImg.size.height);
    float kk = 1.0f;//圖片壓縮係數
    int mm;//壓縮後的大小
    float aa = 1.0f;//圖片壓縮係數變化步長(可變)
    mm = (int)UIImageJPEGRepresentation(normalImg, kk).length;
    while (mm / 1024 > 300) {
        if (kk > aa + aa / 10) {
            kk -= aa;
            if (mm == (int)UIImageJPEGRepresentation(normalImg, kk).length) {
                break;
            }
            mm = (int)UIImageJPEGRepresentation(normalImg, kk).length;
        }else{
            aa /= 10;
        }
    }
    NSLog(@"KK:%f -- aa:%f",kk,aa);
#warning 圖片壓縮
    NSLog(@"第二次處理後:with-----%f height-----%f",normalImg.size.width, normalImg.size.height);
    NSData *newData;
    newData = UIImageJPEGRepresentation(normalImg, kk);//最後壓縮結果
    
    if (newData.length/1024 > 300) {
        
        [APPRequest showAlert:@"提示" message:@"圖片過大"];
       
    }else{
       
       // 上傳圖片網路請求

            
            }
        }];
    }
}
2.釋出時間
        NSDate *  timeDate = [NSDate date];
        NSTimeInterval nowInt = [timeDate timeIntervalSince1970]*1;
        NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
        [dateformatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSDate* publishDate = [dateformatter dateFromString:[demandlist.publish_time substringToIndex:19]];
        NSTimeInterval publishInt = [publishDate timeIntervalSince1970]*1;
        NSTimeInterval cha = nowInt - publishInt;
        NSString *
[email protected]
""; if (cha/3600<1) { timeString = [NSString stringWithFormat:@"%f", cha/60]; timeString = [timeString substringToIndex:timeString.length-7]; timeString = [NSString stringWithFormat:@"%@分鐘前釋出", timeString]; } if (cha/3600>1&&cha/86400<1) { timeString = [NSString stringWithFormat:@"%f", cha/3600]; timeString = [timeString substringToIndex:timeString.length-7]; timeString = [NSString stringWithFormat:@"%@小時前釋出", timeString]; } if (cha/86400>1) { timeString = [NSString stringWithFormat:@"%f", cha/86400]; timeString = [timeString substringToIndex:timeString.length-7]; timeString = [NSString stringWithFormat:@"%@天前釋出", timeString]; }

3.返回字串所佔的尺寸

//返回字串所佔用的尺寸.
-(CGSize)sizeWithFont:(UIFont *)font maxSize:(CGSize)maxSize
{    NSDictionary *attrs = @{NSFontAttributeName : font};   
 return [self boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
}

4.tableView自動滑倒某一行

NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:10 inSection:0];
[[self tableView] scrollToRowAtIndexPath:scrollIndexPath
        atScrollPosition:UITableViewScrollPositionTop animated:YES];
5.tableView重新整理某個分割槽或某行
NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];    
[tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];    
//一個cell重新整理    
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];    
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone]; <span style="font-family: Arial, Helvetica, sans-serif;"> </span>
6.讀取plist檔案
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"plistdemo" ofType:@"plist"];  
   NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
7.關鍵字高亮
    label.text = [NSString stringWithFormat:@" 視野頭條:%@",home.title];

    NSString *str = [NSString stringWithFormat:@" 視野頭條:%@",home.title];

    NSMutableAttributedString *titleStr = [[NSMutableAttributedString alloc]initWithString:str];

    NSRange range = [str rangeOfString:@"視野頭條:"];

    [titleStr addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:range];

    [label setAttributedText:titleStr];
8.去掉字串中的空格
   NSString *str = @"dhak d sh akdl ";
   NSString *strUrl = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
9.UIImage新增生成圓角圖片的擴充套件API
給UIImage新增生成圓角圖片的擴充套件API:
- (UIImage *)imageWithCornerRadius:(CGFloat)radius {
  CGRect rect = (CGRect){0.f, 0.f, self.size};
  UIGraphicsBeginImageContextWithOptions(self.size, NO, UIScreen.mainScreen.scale);
  CGContextAddPath(UIGraphicsGetCurrentContext(),
                   [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius].CGPath);
  CGContextClip(UIGraphicsGetCurrentContext());
  [self drawInRect:rect];
  UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

  UIGraphicsEndImageContext();

  return image;
}
//然後呼叫時就直接傳一個圓角來處理:

imgView.image = [[UIImage imageNamed:@"test"] hyb_imageWithCornerRadius:4];
//最直接的方法就是使用如下屬性設定:
imgView.layer.cornerRadius = 10;
// 這一行程式碼是很消耗效能的
imgView.clipsToBounds = YES;
//好處是使用簡單,操作方便。壞處是離屏渲染(off-screen-rendering)需要消耗效能。對於圖片比較多的檢視上,不建議使用這種方法來設定圓角。通常來說,計算機系統中CPU、GPU、顯示器是協同工作的。CPU計算好顯示內容提交到GPU,GPU渲染完成後將渲染結果放入幀緩衝區。
//簡單來說,離屏渲染,導致本該GPU乾的活,結果交給了CPU來幹,而CPU又不擅長GPU乾的活,於是拖慢了UI層的FPS(資料幀率),並且離屏需要建立新的緩衝區和上下文切換,因此消耗較大的效能。
10.正則法則
//1.驗證郵箱
+ (BOOL)validateEmail:(NSString *)email
{
    NSString *emailRegex = @"[A-Z0-9a-z._%+-][email protected][A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:email];
}
//2.驗證手機(簡單的)
+ (BOOL)validatePhone:(NSString *)phone
{
    NSString *phoneRegex = @"1[3|5|7|8|][0-9]{9}";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];
    return [phoneTest evaluateWithObject:phone];
}
//驗證手機(複雜的)
+ (BOOL)validatePhone:(NSString *)phone
{
       /**
        * 手機號碼
        * 移動:134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
        * 聯通:130,131,132,152,155,156,185,186
        * 電信:133,1349,153,180,189
        */
       NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";
       /**
        10         * 中國移動:China Mobile
        11         * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
        12         */
       NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";
       /**
        15         * 中國聯通:China Unicom
        16         * 130,131,132,152,155,156,185,186
        17         */
       NSString * CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";
       /**
        20         * 中國電信:China Telecom
        21         * 133,1349,153,180,189
        22         */
       NSString * CT = @"^1((33|53|8[09])[0-9]|349)\\d{7}$";
       /**
        25         * 大陸地區固話及小靈通
        26         * 區號:010,020,021,022,023,024,025,027,028,029
        27         * 號碼:七位或八位
        28         */
      // NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";

     NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
     NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
     NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
     NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];

    if (([regextestmobile evaluateWithObject:phone] == YES)
    || ([regextestcm evaluateWithObject:phone] == YES)
    || ([regextestct evaluateWithObject:phone] == YES)
    || ([regextestcu evaluateWithObject:phone] == YES))
    {
        if([regextestcm evaluateWithObject:phone] == YES) {
          NSLog(@"China Mobile");
        } else if([regextestct evaluateWithObject:phone] == YES) {
          NSLog(@"China Telecom");
        } else if ([regextestcu evaluateWithObject:phone] == YES) {
          NSLog(@"China Unicom");
        } else {
          NSLog(@"Unknow");
        }

        return YES;
    }
    else 
    {
        return NO;
    }
}
11.清除快取
// 刪除快取
- (void)removeCache
{
    NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    NSLog(@"%@",cachePath);
    NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachePath];
    for (NSString *p in files) {
        NSString *path = [NSString stringWithFormat:@"%@/%@", cachePath, p];
        if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
            [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
        }
    }
}
// 計算清除的快取大小
- (CGFloat)floatWithPath:(NSString *)path
{
    CGFloat num = 0;
    NSFileManager *man = [NSFileManager defaultManager];
    if ([man fileExistsAtPath:path]) {
        NSEnumerator *childFile = [[man subpathsAtPath:path] objectEnumerator];
        NSString *fileName;
        while ((fileName = [childFile nextObject]) != nil) {
            NSString *fileSub = [path stringByAppendingPathComponent:fileName];
            num += [self fileSizeAtPath:fileSub];
        }
    }
    return num / (1024.0 * 1024.0);
}

//計算單個檔案大小
- (long long)fileSizeAtPath:(NSString *)file
{
    NSFileManager *man = [NSFileManager defaultManager];
    if ([man fileExistsAtPath:file]) {
        return [[man attributesOfItemAtPath:file error:nil] fileSize];
    }
    return 0;
}

12 系統原生態二維碼掃描(包括閃光燈,系統提示音)

#import <AVFoundation/AVFoundation.h>

#import <AudioToolbox/AudioToolbox.h> // 系統提示音
#define SCANVIEW_EdgeTop 40.0
#define SCANVIEW_EdgeLeft 50.0
#define TINTCOLOR_ALPHA 0.2 //淺色透明度
#define DARKCOLOR_ALPHA 0.5 //深色透明度
#define VIEW_WIDTH [UIScreen mainScreen].bounds.size.width
#define VIEW_HEIGHT [UIScreen mainScreen].bounds.size.height
/*
 *********注意 :系統原生態二維碼掃描 蘋果官方目前不支援掃掃描圖冊圖片 ************
 
 1.第一步 引入框架 AVFoundation.framework
 2.第二步 宣告代理:AVCaptureMetadataOutputObjectsDelegate 。 define 幾個東東用來畫框、畫線:
 

 
 */
@interface ViewController ()<AVCaptureMetadataOutputObjectsDelegate>
{
    AVCaptureSession * session;//輸入輸出的中間橋樑
    UIView *AVCapView;//此 view 用來放置掃描框、取消按鈕、說明 label
    UIView *_QrCodeline;//上下移動綠色的線條
    NSTimer *_timer;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self createUI];
    // Do any additional setup after loading the view, typically from a nib.
}
#pragma mark 4.在某個方法中(我是點選掃描按鈕)建立掃描介面,開始掃描
- (void)createUI{

    //建立一個 view 來放置掃描區域、說明 label、取消按鈕
    UIView *tempView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, [UIScreen mainScreen].bounds.size.height )];
    AVCapView = tempView;
    AVCapView.backgroundColor = [UIColor colorWithRed:54.f/255 green:53.f/255 blue:58.f/255 alpha:1];
    
    UIButton *cancelBtn = [[UIButton alloc]initWithFrame:CGRectMake(15, [UIScreen mainScreen].bounds.size.height - 100, 50, 25)];
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(15, 268, 290, 60)];
    label.numberOfLines = 0;
    label.text = @"小提示:將條形碼或二維碼對準上方區域中心即可";
    label.textColor = [UIColor grayColor];
    [cancelBtn setTitle:@"取消" forState: UIControlStateNormal];
    [cancelBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(touchAVCancelBtn) forControlEvents:UIControlEventTouchUpInside];
    [AVCapView addSubview:label];
    [AVCapView addSubview:cancelBtn];
    [self.view addSubview:AVCapView];
    
    //畫上邊框
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(SCANVIEW_EdgeLeft, SCANVIEW_EdgeTop, VIEW_WIDTH- 2 * SCANVIEW_EdgeLeft, 1)];
    topView.backgroundColor = [UIColor whiteColor];
    [AVCapView addSubview:topView];
    
    //畫左邊框
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(SCANVIEW_EdgeLeft, SCANVIEW_EdgeTop , 1,VIEW_WIDTH - 2 * SCANVIEW_EdgeLeft )];
    leftView.backgroundColor = [UIColor whiteColor];
    [AVCapView addSubview:leftView];
    
    //畫右邊框
    UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(SCANVIEW_EdgeLeft + VIEW_WIDTH- 2 * SCANVIEW_EdgeLeft, SCANVIEW_EdgeTop , 1,VIEW_WIDTH - 2 * SCANVIEW_EdgeLeft + 1)];
    rightView.backgroundColor = [UIColor whiteColor];
    [AVCapView addSubview:rightView];
    
    //畫下邊框
    UIView *downView = [[UIView alloc] initWithFrame:CGRectMake(SCANVIEW_EdgeLeft, SCANVIEW_EdgeTop + VIEW_WIDTH- 2 * SCANVIEW_EdgeLeft,VIEW_WIDTH - 2 * SCANVIEW_EdgeLeft ,1 )];
    downView.backgroundColor = [UIColor whiteColor];
    [AVCapView addSubview:downView];
    
    //閃光燈
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(150, [UIScreen mainScreen].bounds.size.height - 100, 80, 35);
    [btn setTintColor:[UIColor grayColor]];
    
    [btn setTitle:@"閃光燈" forState:UIControlStateNormal];
    [btn addTarget:self action: @selector(OPEN:) forControlEvents:UIControlEventTouchUpInside];
    [AVCapView  addSubview:btn];
   
    
    //畫中間的基準線
    _QrCodeline = [[UIView alloc] initWithFrame:CGRectMake(SCANVIEW_EdgeLeft + 1, SCANVIEW_EdgeTop, VIEW_WIDTH- 2 * SCANVIEW_EdgeLeft - 1, 2)];
    _QrCodeline.backgroundColor = [UIColor greenColor];
    [AVCapView addSubview:_QrCodeline];
    
    
    // 先讓基準線運動一次,避免定時器的時差
    [UIView animateWithDuration:1.2 animations:^{
        
        _QrCodeline.frame = CGRectMake(SCANVIEW_EdgeLeft + 1, VIEW_WIDTH - 2 * SCANVIEW_EdgeLeft + SCANVIEW_EdgeTop , VIEW_WIDTH - 2 * SCANVIEW_EdgeLeft - 1, 2);
        
    }];
    
    [self performSelector:@selector(createTimer) withObject:nil afterDelay:0.4];
    
    
    AVCaptureDevice * device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    //建立輸入流
    AVCaptureDeviceInput * input = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
    //建立輸出流
    AVCaptureMetadataOutput * output = [[AVCaptureMetadataOutput alloc]init];
    //設定代理 在主執行緒裡重新整理
    [output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
    
    //初始化連結物件
    session = [[AVCaptureSession alloc]init];
    //高質量採集率
    [session setSessionPreset:AVCaptureSessionPresetHigh];
    
    [session addInput:input];
    [session addOutput:output];
    //設定掃碼支援的編碼格式(如下設定條形碼和二維碼相容)
    [email protected][AVMetadataObjectTypeQRCode,AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode128Code];
    
    AVCaptureVideoPreviewLayer * layer = [AVCaptureVideoPreviewLayer layerWithSession:session];
    layer.videoGravity=AVLayerVideoGravityResizeAspectFill;
    layer.frame = CGRectMake(SCANVIEW_EdgeLeft, SCANVIEW_EdgeTop, VIEW_WIDTH- 2 * SCANVIEW_EdgeLeft, 220);
    [AVCapView.layer insertSublayer:layer atIndex:0];
    //開始捕獲
    [session startRunning];

}
#pragma mark 呼叫閃光燈
- (void)OPEN:(UIButton *)btn{

    btn.selected = !btn.isSelected;
    
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    
    if ([device hasTorch]) {
        
        [device lockForConfiguration:nil];
        
    if (btn.selected) {
        
        [device setTorchMode:AVCaptureTorchModeOn];
        
    }else{
    
          [device setTorchMode:AVCaptureTorchModeOff];
    }
           [device unlockForConfiguration];

    }
}
- (void)touchAVCancelBtn{

    //取消按鈕的響應時間
}
#pragma mark 5.實現定時器、還有基準線的滾動方法
- (void)createTimer
{
    _timer=[NSTimer scheduledTimerWithTimeInterval:1.1 target:self selector:@selector(moveUpAndDownLine) userInfo:nil repeats:YES];
}

- (void)stopTimer
{
    if ([_timer isValid] == YES) {
        [_timer invalidate];
        _timer = nil;
    }
    
}
// 滾來滾去 :D :D :D
- (void)moveUpAndDownLine
{
    CGFloat YY = _QrCodeline.frame.origin.y;
    
    if (YY != VIEW_WIDTH - 2 * SCANVIEW_EdgeLeft + SCANVIEW_EdgeTop ) {
        [UIView animateWithDuration:1.2 animations:^{
            _QrCodeline.frame = CGRectMake(SCANVIEW_EdgeLeft + 1, VIEW_WIDTH - 2 * SCANVIEW_EdgeLeft + SCANVIEW_EdgeTop , VIEW_WIDTH - 2 * SCANVIEW_EdgeLeft - 1,2);
        }];
    }else {
        [UIView animateWithDuration:1.2 animations:^{
            _QrCodeline.frame = CGRectMake(SCANVIEW_EdgeLeft + 1, SCANVIEW_EdgeTop, VIEW_WIDTH - 2 * SCANVIEW_EdgeLeft - 1,2);
        }];
        
    }
}
#pragma mark 6.掃描成功後,想幹嘛幹嘛,就在這個代理方法裡面實現就行了

-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection{
    if (metadataObjects.count>0) {
        //[session stopRunning];
        AVMetadataMachineReadableCodeObject * metadataObject = [metadataObjects objectAtIndex : 0 ];
        //輸出掃描字串
        NSLog(@"%@",metadataObject.stringValue);
        AudioServicesPlaySystemSound(1307);
        [session stopRunning];
        [self stopTimer];
        //[AVCapView removeFromSuperview];
      
    }
}

13.webView計算高度

//第一種:

- (void)webViewDidFinishLoad:(UIWebView *)webView{

float height = [[webView stringByEvaluatingJavaScriptFromString:@document.body.offsetHeight;] floatValue];

//document.body.scrollHeight

}

 

//第二種:

 

- (void) webViewDidFinishLoad:(UIWebView *)webView

{

CGRect frame = webView.frame;

CGSize fittingSize = [webView sizeThatFits:CGSizeZero];

frame.size = fittingSize;

webView.frame = frame;

}

 

//另外一種

- (void)viewDidLoad {

[super viewDidLoad];

webview.delegate = self;

[webview loadHTMLString:@

fdasfda

baseURL:nil];

}

- (void)webViewDidFinishLoad:(UIWebView *)webView

{

NSString *output = [webview stringByEvaluatingJavaScriptFromString:@document.getElementByIdx_x_x_x(foo).offsetHeight;];

NSLog(@height: %@, output);

}


14.URL

14.1  支付寶支付流程

14.2  KVO詳解

14.6 推送


相關推薦

iOS開發一些常用方法

1.壓縮圖片#pragma mark 處理圖片 - (void)useImage:(UIImage *)image { NSLog(@"with-----%f heught-----%f",image.size.width,image.size.height);

jquery項目一些常用方法

dev touch wid sets add subst arch param 時間 1、獲取url中的參數 function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&am

pytorch一些常用方法的總結

主要介紹一些pytorch框架常用的方法:2、我個人也是 pytorch 的初學者,我以一個初學者的身份來簡單介紹torch的使用,pytorch是使用GPU和CPU優化的深度張量庫,torch中最重要的一個數據型別就是Tensor(張量),我們計算的時候用Tensor來計算

iOS開發一些實用小程式碼

1.判斷郵箱格式是否正確的程式碼: //利用正則表示式驗證 -(BOOL)isValidateEmail:(NSString *)email { NSString *emailRegex = @"[A-Z0-9a-z._%+-][email protected

iOS開發基礎常用細節問題處理

35. 九宮格 //九宮格方法1: 巢狀for 迴圈     for (int a = 0 ; a <2; a ++) {         for (int b = 0 ; b < 3 ; b++) {             UIButton * btn = [UIButton but

安卓一些常用方法

根據手機的解析度從 dp 的單位 轉成為 px(畫素) :切勿在返回值後面+0.5增加精度 因為在某些低解析度跟高分辨的手機上會有大的誤差 public static int dip2px(Context context, float dpValue) { fin

ios開發常用的幾種輔助方法

//1.Keychain本地長期鍵值儲存 //刪除 +(void)deleteStringForKey:(NSString *)aKey { NSMutableDictionary *query = [NSMutableDictionary dictionary];

iOS開發常用的宏

tar lin iter standard ffi ant height same alt OC對象判斷是否為空? 字符串是否為空 #define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] ||

關於機器學習一些常用方法的補充

機器學習 k近鄰 apriori pagerank前言 機器學習相關算法數量龐大,很難一一窮盡,網上有好事之人也評選了相關所謂十大算法(可能排名不分先後),它們分別是: 1. 決策樹2. 隨機森林算法3. 邏輯回歸4. 支持向量機5. 樸素貝葉斯6

tp5.0及其常用方法一些函數方法(自己看)和技巧(不斷添加

pro xtend yml 數據庫操作 apach txt 圖標 index run 1.目錄結構 2.路由 3..控制器 4.模型寫法 5.視圖標簽 6.數據庫操作 7.表單驗證 --------------------------- 1.目錄結構

iOS開發UI篇—IOS開發Xcode的一些使用技巧

pen 檢查 elf eight return ui篇 bar mage \n iOS開發UI篇—IOS開發中Xcode的一些使用技巧 一、快捷鍵的使用 經常用到的快捷鍵如下: 新建 shift + cmd + n 新建項目 cmd + n

JavaScriptArray型別一些常用方法

與其他語言中的陣列有著極大的區別,JavaScript中的陣列,每一項都可以儲存任何型別的資料,且陣列的大小可以動態的調整,即可以隨著資料的新增自動增長以容納新增的資料。 1.陣列的建立方式 建立陣列的基本方式有兩種 (1)使用Array建構函式 var colors = new Ar

JS一些常用的陣列方法

<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=d

J2EE一些常用方法和細節整理

1.setAttribute、getAttribute方法 方法 描述 注意點 void setAttribute(String name,Object o) 設定屬性的名稱及內容

淺談自定義View一些常用的回撥方法

1. 構造方法 1.public View(Context context) 2.public View(Context context, @Nullable AttributeSet attrs) 3.public View(Context context, @Nulla

執行緒一些常用方法的用法 join()、yield()、sleep()、wait()、notify()、notifyAll()

1.執行緒休眠sleep();:執行緒有優先順序,但是我們可以用此方法人為的改變它們的優先順序,讓執行緒暫停,它其他執行緒獲得分配空間。 用法:Thread.sleep(2000);//休眠兩秒 2.執行緒讓步yield();就是讓出自己的分配空間給其他執行

iOS開發一些常見的警告解決方案(更新。。。)

Unknown pattern color for the Background Color attribute 1.背景色屬性為未知模式的顏色 解決:預設xib裡面控制元件的背景色為Default。如果出現警告,可能是你定義的顏色Xcode啟動

Android開發一些被冷落但卻很有用的類和方法

來自:http://luckyandyzhang.github.io/ Resources.getIdentifier : 這個我 用過,記得以前做過一個面板切換功能,可以通過這個方法從面板包 獲取面板資源。 (面板包的資源名稱和 主包的資源名稱id 名是一樣的

關於iOS開發圖片處理的一些積累(CoreGraphic、CoreImage、GPUImage、OpenGL)

Core Image 前言 貌似公司最近的專案都是和圖片處理有關,拍拍專案中需要將圖片處理成buffer傳到影象匹配拼接演算法中,需要從原圖中摳出一定範圍的影象再貼到新的背景圖中,需要對靜態圖片進行濾鏡操作等等,所以對這方面接觸的相對多一些。

javascript vue專案開發常用公共方法

本篇文章純屬乾貨,包含了筆者在實際專案開發中經常用到的一些公共通用方法,希望可以幫助大家。 部分方法適用ReactNative import { PixelRatio, Dimensions, Platform, findNodeHandl