Basic knowledge of IOS development-fragmentation 46, basic knowledge of ios-46

Source: Internet
Author: User

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()"];}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.