• iOS Coding项目片段记录(二)


    1.加快CocoaPod 安装

    $ pod install --no-repo-update 

    2.判断字符串是否为null  nul nil等情况

    - (NSString *)checkStringIsNullString:(NSString *)str  {
        
        if ([[NSString stringWithFormat:@"%@",str] isEqualToString:@""]|| ([NSString stringWithFormat:@"%@",str] == nil) ||[[NSString stringWithFormat:@"%@",str]isEqualToString:@"(null)"] ||[[NSString stringWithFormat:@"%@",str] isEqualToString:@"null"]||[[NSString stringWithFormat:@"%@",str] isEqualToString:@"nul"])
        {
            str = @"0";
            return str;
        }
        return str;
        
    }

    3.判断一张view 是否被加载过用 nil == view.superview

    if (nil == view.superview) {     //判断一个view 是否被加载过    如果被加载过,它的superview就不会是nil
                CGRect frame = scrollView0.frame;
                frame.origin.x = frame.size.width * page;
                frame.origin.y = 0;
                view.frame = frame;
                [scrollView0 addSubview:view];
            }

     4.WebView图片自适应模式

    - (void)webViewDidFinishLoad:(UIWebView *)webView {
      NSString *js = @"function imgAutoFit() { 
         var imgs = document.getElementsByTagName('img'); 
         for (var i = 0; i < imgs.length; ++i) {
            var img = imgs[i];   
            img.style.maxWidth = %f;   
         } 
      }";
      js = [NSString stringWithFormat:js, [UIScreen mainScreen].bounds.size.width - 20];
     
      [webView stringByEvaluatingJavaScriptFromString:js];
      [webView stringByEvaluatingJavaScriptFromString:@"imgAutoFit()"];
    }

    5.强制APP退出

    - (void)exitApplication {
        AppDelegate *app = [UIApplication sharedApplication].delegate;
        UIWindow *window = app.window;
        [UIView animateWithDuration:1.0f animations:^{
            window.alpha = 0;
        } completion:^(BOOL finished) {
            exit(0);
        }];
    }
  • 相关阅读:
    CDN 机制
    canvas绘制旋转图形
    前端资源网站
    css中的em用法
    响应式网页设计【转载】
    闭包与非闭包
    跨域文档之间的访问
    ajax跨域之---服务器端代理实现
    jsonp跨域实现
    freemarker 命名空间
  • 原文地址:https://www.cnblogs.com/741162830qq/p/6030734.html
Copyright © 2020-2023  润新知