- 更改状态栏的背景颜色
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = [UIColor redColor];
}
- 设置alertView内容对齐方式NSTextAlignment
NSString *titleString = @"发现新版本 v1.1";
NSString *messageString = @"1.哈哈\n2.嘿嘿\n3.呵呵";
UIAlertController * alertView = [UIAlertController alertControllerWithTitle:titleString message:messageString preferredStyle:UIAlertControllerStyleAlert];
//需要遍历6层subViews(没写for循环,可自行修改)
UIView *subView1 = alertView.view.subviews[0];
UIView *subView2 = subView1.subviews[0];
UIView *subView3 = subView2.subviews[0];
UIView *subView4 = subView3.subviews[0];
UIView *subView5 = subView4.subviews[0];
UILabel *title = subView5.subviews[0];
UILabel *message = subView5.subviews[1];
title.textAlignment = NSTextAlignmentLeft;
message.textAlignment = NSTextAlignmentLeft;
UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"稍候再说" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
UIAlertAction * maskAction = [UIAlertAction actionWithTitle:@"立即更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
[alertView addAction:cancelAction];
[alertView addAction:maskAction];
[self presentViewController:alertView animated:YES completion:nil];
-
URL编码解码
//URLDEcode
- (NSString)encodeString:(NSString)unencodedString{
NSString *encodedString = (NSString )
CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(CFStringRef)unencodedString,
NULL,
(CFStringRef)@"!'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8));
return encodedString;
}
//URLDEcode
-(NSString )decodeString:(NSString)encodedString{
NSString *decodedString = (__bridge_transfer NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL,
(__bridge CFStringRef)encodedString,
CFSTR(""),
CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
return decodedString;
} -
使用Xcode查找项目中的中文字符串
1. 打开”Find Navigator”
2. 切换搜索模式到 “Find > Regular Expression”
3. 输入@"[^"]*[\u4E00-\u9FA5]+[^"\n]*?" (swift请去掉”@” 输入@"[^"]*[\u4E00-\u9FA5]+[^"\n]*?" 就好了)
- 去除Xcode多余的模拟器
1.关闭xcode
2.终端输入 sudo killall -9 com.apple.CoreSimulator.CoreSimulatorService 输入你的电脑密码
3.终端输入 rm -rf ~/Library/Developer/CoreSimulator/Devices
- git push文件太大 HTTP Error: 413 Request Entity Too Large
用http链接传的代码,文件太大,需配置文件上传最大限制或者用ssh上传,这里说的是ssh上传
1.先检查下有没有安装ssh,一般都安装了,没安装的自己百度
* 打开终端:$ ssh -v
出现OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-e escape_char] [-F configfile]
[-I pkcs11] [-i identity_file]
[-L [bind_address:]port:host:hostport]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-R [bind_address:]port:host:hostport] [-S ctl_path]
[-W host:port] [-w local_tun[:remote_tun]]
[user@]hostname [command]
显示这个表示已安装
2.获取ssh key
$ open ~/.ssh
打开id_rsa.pub,里面的内容就是ssh key了,全复制到git的ssh key配置项,添加
之后,采用ssh链接上传代码就OK了(登录你的github账号,从又上角的设置进入,然后点击菜单栏的 SSH key 进入页面添加 SSH key。)
- 目录路径
//获取程序Documents目录路径
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString * documentsDirectory = [paths objectAtIndex:0];
//获取程序app文件所在目录路径
NSHomeDirectory();
//获取程序tmp目录路径
NSTemporaryDirectory();
//获取程序应用包路径
[[NSBundle mainBundle] resourcePath];
或
[[NSBundle mainBundle] pathForResource:@"info"ofType:@"txt"];
- PUSH和POP动画
1. push默认动画效果
CATransition *transition = [CATransition animation];
transition.duration = 0.25f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
transition.delegate = self;
[self.contentView.layer addAnimation:transition forKey:nil];
[self.contentView addSubview:self.productDetailController.view];
PS:self.contentView是工程中的UIView,self.productDetailController是工程中的controller
只需要把两者替换成合适的内容即可用
2. pop默认动画效果
CATransition *transition = [CATransition animation];
transition.duration = 0.25f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
transition.delegate = self;
[self.view.superview.layer addAnimation:transition forKey:nil];
[self.view removeFromSuperview];
- 切换根控制器
1. 第一种
[UIView transitionWithView:[[UIApplication sharedApplication].delegate window]
duration:0.4
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
BOOL oldState = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
[[[UIApplication sharedApplication].delegate window] setRootViewController:vc];
[UIView setAnimationsEnabled:oldState];
}
completion:NULL];
2. 第二种
for (UIView * subView in appDelegate.window.subviews)
{
[subView removeFromSuperview];
}
appDelegate.window.rootViewController = [[RootViewController alloc] initialize];
3. 第三种
- (void)setRootViewController:(UIViewController *)rootViewController
{
//remove old rootViewController's sub views
for (UIView* subView in self.rootViewController.view.subviews)
{
[subView removeFromSuperview];
}
//remove old rootViewController's view
[self.rootViewController.view removeFromSuperview];
//set new rootViewController
[super setRootViewController:rootViewController];
//remove empty UILayoutContainerView(s) remaining on root window
for (UIView *subView in self.subviews)
{
if (subView.subviews.count == 0)
{
[subView removeFromSuperview];
}
}
}
-
检测UIPickView是否在滑动
- (BOOL)isPickViewScrolling:(UIView *)view { if ([view isKindOfClass:[UIScrollView class]]) { UIScrollView *scrollView = (UIScrollView *)view; if (scrollView.dragging || scrollView.decelerating) { return YES; } } for (UIView *theSubView in view.subviews) { if ([self isPickViewScrolling:theSubView]) { return YES; } } return NO; }
-
webView隐藏上下滚动出边界时的黑色的图片
for (UIView *_aView in [_webView subviews])
{
if ([_aView isKindOfClass:[UIScrollView class]])
{
[(UIScrollView *)_aView setShowsVerticalScrollIndicator:NO];
//右侧的滚动条
[(UIScrollView *)_aView setShowsHorizontalScrollIndicator:NO];
//下侧的滚动条
for (UIView *_inScrollview in _aView.subviews)
{
if ([_inScrollview isKindOfClass:[UIImageView class]])
{
_inScrollview.hidden = YES; //上下滚动出边界时的黑色的图片
}
}
}
}
网友评论