IOS開發基礎知識--片段46,ios基礎知識--46

來源:互聯網
上載者:User

IOS開發基礎知識--片段46,ios基礎知識--46

1:帶中文的URL處理

// http://static.tripbe.com/videofiles/視頻/我的自拍視頻.mp4NSString *path  = (__bridge_transfer NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL,(__bridge CFStringRef)model.mp4_url, CFSTR(""),CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));

2:取WebView高度

- (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:UIView的部分圓角問題

UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(120, 10, 80, 80)];view2.backgroundColor = [UIColor redColor];[self.view addSubview:view2]; UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view2.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];maskLayer.frame = view2.bounds;maskLayer.path = maskPath.CGPath;view2.layer.mask = maskLayer;//其中,byRoundingCorners:UIRectCornerBottomLeft |UIRectCornerBottomRight//指定了需要成為圓角的角。該參數是UIRectCorner類型的,可選的值有:* UIRectCornerTopLeft* UIRectCornerTopRight* UIRectCornerBottomLeft* UIRectCornerBottomRight* UIRectCornerAllCorners

4:強制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);    }];}

5:修改預留位置顏色和大小

textField.placeholder = @"請輸入使用者名稱";  [textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];  [textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];

6:取消系統的返回手勢

self.navigationController.interactivePopGestureRecognizer.enabled = NO;

7:改WebView字型/顏色

UIWebView設定字型大小,顏色,字型: UIWebView無法通過自身的屬性設定字型的一些屬性,只能通過html代碼進行設定 在webView載入完畢後:

- (void)webViewDidFinishLoad:(UIWebView *)webView {      NSString *str = @"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '60%'";      [webView stringByEvaluatingJavaScriptFromString:str]; }或者加入以下代碼NSString *jsString = [[NSString alloc] initWithFormat:@"document.body.style.fontSize=%f;document.body.style.color=%@",fontSize,fontColor];   [webView stringByEvaluatingJavaScriptFromString:jsString];

8: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個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.