1,ios setting UITableView does not show extra empty cells
Self.tableView.tableFooterView = [[UIView alloc] Initwithframe:cgrectzero];
2,ios UIWebView Height Size Adaptive
- (void)webViewDidFinishLoad:(UIWebView*)webView //网页加载完成的时候调用
{ CGRect frame = webView.frame; CGSize fittingSize = [webView sizeThatFits:CGSizeZero]; frame.size = fittingSize; webView.frame = frame;}3, set the UITableViewCell's selected background color and select the Font color method//设置UITableViewCell的选中背景颜色的方法 UIView *view = [[UIView alloc]init]; view.backgroundColor=[UIColor redColor]; cell.selectedBackgroundView=view;//设置UITableViewCell的选中字体颜色的方法:cell.selectedTextColor=[UIColor blackColor];//默认显示为白色4,ios setting the background color transparency of the UITableViewCell//设置UIColor为clearColor:cell.backgroundColor=[UIColor clearColor];//或者,设置颜色透明度为0: cell.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.0f];How to hide Tabbar when 5,ios jump interface//1.设置self.tabBarController.tabBar.hidden=YES; self.tabBarController.tabBar.hidden=YES;//2.如果在push跳转时需要隐藏tabBar,设置self.hidesBottomBarWhenPushed=YES; self.hidesBottomBarWhenPushed=YES; NextViewController *next=[[NextViewController alloc]init]; [self.navigationController pushViewController:next animated:YES]; self.hidesBottomBarWhenPushed=NO;//并在push后设置self.hidesBottomBarWhenPushed=NO;//这样back回来的时候,tabBar会恢复正常显示。6, in iOS development, set the Tabbaritem.image picture rendering mode Imagewithrenderingmode property to Uiimagerenderingmodealwaysoriginal, you can make the picture display the original state Self.tabbaritem.image=[[uiimage imagenamed:images[i] [imagewithrenderingmode:uiimagerenderingmodealwaysoriginal] ; 7, when using [Nsurl urlwithstring:urlstring] to generate a URL object, if you have Chinese characters, the iOS client does not make the network request correctly nsstring* encodedstring = [urlstring Stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]; 8,uiwebview Loading data and highly adaptive
When a URL address contains Chinese characters or other non-standard URL characters, the URL address needs to be encoded. NSString provides encoding and decoding methods:
Code: stringbyaddingpercentescapesusingencoding
| 123 |
NSString *urlString=[NSString stringWithFormat:@"http://www.xxxx.com/?param=%@",@"中文"];urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; |
Decoding: stringbyreplacingpercentescapesusingencoding
| 1 |
NSString *urlStr = [@"xxx"stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; |
UIWebView three ways to load data
1>-(void) Loadrequest: (nsurlrequest *) request;
| 123 |
NSURL *url = [NSURL URLWithString:urlString]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [self.webView loadRequest:request]; |
Loads the URL address directly.
2>-(void) loadhtmlstring: (NSString *) string BaseURL: (Nsurl *) BaseURL;
If you get an HTML string, you can load it with this method.
3>-(void) LoadData: (NSData *) data MIMEType: (NSString *) MIMEType textencodingname: (NSString *) textencodingname BaseURL: (Nsurl *) BaseURL;
| 123 |
NSURL *url = [NSURL URLWithString:urlString]; NSData *data=[NSData dataWithContentsOfURL:url]; [self.webView loadData:data MIMEType:@"text/html"textEncodingName:@"GBK"baseURL:nil]; |
Encoding format has GB2312, GBK, UTF-8 and many other kinds, when the URL address of the encoding format is more special, you can use this method to load.
UIWebView highly Adaptive
1> implements the following event method to make the WebView size highly adaptive:
Abide by the protocol uiwebviewdelegate, set up Agent self.webview.delegate=self;
Implementation-(void) Webviewdidfinishload: (UIWebView *) WebView event method
| 1234567 |
- ( void ) Webviewdidfinishload: (uiwebview *) webview { when the Web page is loaded, cgrect frame = webview.frame;      cgsize fittingsize = [webview sizethatfits:cgsizezero];      frame.size = fittingsize;      webview.frame = frame; } |
The WebView adaptive height obtained by this method is fixed, and if the height of the displayed HTML exceeds the height of webview, it is displayed as a screen scroll.
2> If you want the height of the webview to be equal to the actual height of the displayed HTML, that is, how high the HTML is displayed, and how high the webview height is, use the following method
| 12345 |
- (void)webViewDidFinishLoad:(UIWebView *)webView{ NSInteger height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"] integerValue]; self.webView.frame=CGRectMake(0, 0, self.view.frame.size.width,height);} |
Stringbyevaluatingjavascriptfromstring can achieve UIWebView and JavaScript interaction, it is convenient to manipulate the page elements in the UIWebView.
Although this method can make the webview height for the displayed HTML actual height, the effect is not too good to scroll down when the height exceeds the screen.
3> to implement scrolling with the height of the webview at the height of the actual HTML, you can combine the two methods to place the WebView on a scrollview of a suitable size:
| 1234567891011121314 |
- (void)webViewDidFinishLoad:(UIWebView *)webView{ CGRect frame = webView.frame; CGSize fittingSize = [webView sizeThatFits:CGSizeZero]; frame.size = fittingSize; webView.frame = frame; NSInteger height = [[webView stringByEvaluatingJavaScriptFromString: @"document.body.scrollHeight"] integerValue]; self.scrollView.contentSize=CGSizeMake(self.view.frame.size.width, height); [self.scrollView addSubview:self.webView];} |
In addition, the following three pieces of code effect basically the same:
[WebView stringbyevaluatingjavascriptfromstring:@ "Document.body.scrollHeight"];
[WebView stringbyevaluatingjavascriptfromstring:@ "Document.body.offsetHeight"];
[WebView stringbyevaluatingjavascriptfromstring:@ "Document.body.clientHeight"];
Common code for "iOS Learning notes"