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); }]; }
如果错过了一天,那么真的就错过一天。不抛弃,不放弃。点一盏心灯给自己。