Basic knowledge of IOS development-fragmentation 46, basic knowledge of ios-46
1: URL Processing with Chinese characters
// Required * path = (_ bridge_transfer NSString *) equals (NULL, (_ bridge cfstringref1_model.mp4 _ url, CFSTR (""), equals (NSUTF8StringEncoding ));
2: Take the WebView height
- (void)webViewDidFinishLoad:(UIWebView *)webView { CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue]; CGRect frame = webView.frame; webView.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, height); }
3: Some rounded corners of UIView
UIView * view2 = [[UIView alloc] initWithFrame: CGRectMake (120, 10, 80, 80)]; view2.backgroundColor = [UIColor redColor]; [self. view addSubview: view2]; UIBezierPath * maskPath = [UIBezierPath paths: view2.bounds byRoundingCorners: outputs | UIRectCornerBottomRight cornerRadii: CGSizeMake (10, 10)]; CAShapeLayer * maskLayer = [[CAShapeLayer alloc] init]; maskLayer. frame = view 2. bounds; maskLayer. path = maskPath. CGPath; view2.layer. mask = maskLayer; // among them, byRoundingCorners: UIRectCornerBottomLeft | UIRectCornerBottomRight // specifies the corner to be rounded. This parameter is of the UIRectCorner type and has the following optional values: * UIRectCornerTopLeft * UIRectCornerTopRight * UIRectCornerBottomLeft * UIRectCornerBottomRight * UIRectCornerAllCorners
4: force the App to exit directly
- (void)exitApplication { AppDelegate *app = [UIApplication sharedApplication].delegate; UIWindow *window = app.window; [UIView animateWithDuration:1.0f animations:^{ window.alpha = 0; } completion:^(BOOL finished) { exit(0); }];}
5. Modify the placeholder color and size.
TextField. placeholder = @ "Enter the user name"; [textField setValue: [UIColor redColor] forKeyPath: @ "_ placeholderLabel. textColor "]; [textField setValue: [UIFont boldSystemFontOfSize: 16] forKeyPath: @" _ placeholderLabel. font "];
6. Cancel the system response gesture.
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
7: Change the WebView Font/color
UIWebView: you cannot set the font size, color, and font through its own attributes. You can only set the font attributes using html code after loading the webView:
-(Void) webViewDidFinishLoad :( UIWebView *) webView {NSString * str = @ "document. getElementsByTagName ('body') [0]. style. webkitTextSizeAdjust = '000000' "; [webView stringByEvaluatingJavaScriptFromString: str];} or add the following code NSString * jsString = [[NSString alloc] initWithFormat: @" document. body. style. fontSize = % f; document. body. style. color = % @ ", fontSize, fontColor]; [webView stringByEvaluatingJavaScriptFromString: jsString];
8: WebView image adaptive screen
- (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()"];}