标签:des style blog http java color
1、设置tableview返回时取消选中状态
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.tableview deselectRowAtIndexPath:self.tableview.indexPathForSelectedRow animated:YES];
}
2、设置UIPickerView默认选中
[pickerView selectRow:5 inComponent:0 animated:NO];
3、设置应用电池栏颜色
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
4、检测网络连接状态 (添加SystemConfiguration.framework 和Reachability.h 和Reachability.m)
if (([Reachability reachabilityForInternetConnection].currentReachabilityStatus == NotReachable) &&
([Reachability reachabilityForLocalWiFi].currentReachabilityStatus == NotReachable)) {
NSLog(@"无网络连接");
}
5、图片缩放
UIImage *image = [[UIImage alloc] initWithData:self.activeDownload];
if (image.size.width != kAppIconHeight && image.size.height != kAppIconHeight)
{
CGSize itemSize = CGSizeMake(kAppIconHeight, kAppIconHeight);
UIGraphicsBeginImageContext(itemSize);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[image drawInRect:imageRect];
self.appRecord.appIcon = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
else
{
self.appRecord.appIcon = image;
}
6、设置UIWenview背景透明的方法
webview.backgroundColor = [UIColor clearColor];
webview.opaque = NO;
在 网页里设置:
<body style="
7、js控制UIWebvie
js里:
<script>
function jump()
{
var clicked=true;
window.location="/clicked"; //改变URL 注意:要使用"/"分隔符
alert("js alert :jump");
}
</script>
oc里:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
//获取URL并且做比较,判断是否触发了JS事件,注意有"/"
if ([request.mainDocumentURL.relativePath isEqualToString:@"/clicked"]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"you click me" message:@"clicked" delegate:nilcancelButtonTitle:@"sure" otherButtonTitles:@"cancel", nil];
[alertView show];
[alertView release];
return false;
}
return true;
}
8、UIWebview加载本地html
UIWebView类没有修改缩放系数的方法,我们只能用HTML代码来做。Meta标签可以设置viewport,而viewport就包含了初始化缩放系数的参数。
META标签如下所示:
<meta name="viewport"content="minimum-scale=0.6; maximum-scale=5; initial-scale=1; user-scalable=yes; width=640">
可以使用的参数有:
- (void)applicationWillResignActive:(UIApplication *)application
11、NSData 与NSString 互转
NSData* xmlData = [@"testdata" dataUsingEncoding:NSUTF8StringEncoding];
NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
12、图片转圆角
效果图
首先导入头文件:#import <QuartzCore/QuartzCore.h>
UIImageView * headerImage = [[UIImageView alloc] initWithFrame:CGRectMake(10.0, 10.0, 64.0, 64.0)];
headerImage.image = contactPhoto;
CALayer * layer = [headerImage layer];
[layer setMasksToBounds:YES];
[layer setCornerRadius:10.0];
[layer setBorderWidth:1.0];
[layer setBorderColor:[[UIColor blackColor] CGColor]];
[contactHeader addSubview:headerImage];
13、將图片保存到相册的代码
UIImageWriteToSavedPhotosAlbum(Uiimage, nil, nil, nil);
14、去掉tableview 的线
[self.tableview setSeparatorStyle:UITableViewCellSeparatorStyleNone];
15、UILable文字加阴影
titleText.shadowColor = [UIColor blackColor];
titleText.shadowOffset = CGSizeMake(0, -1.0);
16、plist文件转NSDictionary
NSBundle *bundle = [NSBundle mainBundle];
//取得文件路径
NSString *plistPath = [bundle pathForResource:@"cityData" ofType:@"plist"];
//读取到一个NSDictionary
cityDictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
17、隐藏tabbar
- (void) hideTabBar:(BOOL) hidden {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0];
for(UIView *view in self.tabBarController.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
if (hidden) {
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, 480-49, view.frame.size.width, view.frame.size.height)];
}
}
else
{
if (hidden) {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480-49)];
}
}
}
[UIView commitAnimations];
}
标签:des style blog http java color
原文地址:http://www.cnblogs.com/android-dev/p/3811740.html