1, 转换坐标:
convertRect: toView:
例如: CGRect rect = [cell convertRect: btn.frame toView: self.view];
2,svn忽略文件,不上传pod,只上传Podfile
Podfile 文件是记录pod 需要引入的文件内容的,需要上传
Cornerstone->preferences...->Subversion->取消勾选(Use default global ignores)
把下面的复制进去, 需要忽略的:
//xcode本身的文件
.xcuserdatad, .xcscmblueprint, xcuserdata,
//pods文件夹和锁定
Pods, Podfile.lock
然后save
3、iTunes拖入(推荐)
这种方法十分方便。具体步骤请看动态图:
注意:itunes里的“我的应用程序”是指电脑上的程序,不要求联机,可以把里面的app删除
NSLog(@"%@", [[NSBundlemainBundle]pathForAuxiliaryExecutable:@""]);
4,根据文字获取size
//根据文字的长度和字号返回size
+(CGSize)StringWithSize:(NSString*)str fontSize:(CGFloat)fontSize{
NSDictionary *attrs =@{NSFontAttributeName: [UIFont boldSystemFontOfSize: fontSize]};
CGSize size=[strsizeWithAttributes:attrs];
return size;
}
5,模型中出现id
这时只需要重写- (void)setValue:(id)value forUndefinedKey:(NSString *)key 方法即可
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
if([key isEqualToString:@"id"])
self.userid = value;
}
6,代码段保存的路径
~/Library/Developer/Xcode/UserData/CodeSnippets
7,分割字符串
NSString *list = @"Karin, Carrie, David";
可以用上面的函数得到一个字符串数组:
NSArray *listItems = [list componentsSeparatedByString:@", "];
8,把后台出给的秒转换成年月日时分秒
- (NSString *)returndate:(NSNumber *)num{
NSString *str1=[NSString stringWithFormat:@"%@",num];
int x = [[str1 substringToIndex:10] intValue];
NSDate *date1 = [NSDate dateWithTimeIntervalSince1970:x];
NSDateFormatter *dateformatter=[[NSDate Formatter alloc]init];
[dateformatter setDateFormat:@"yyyy-MM-dd hh:mm"];//12格式
//[dateformattersetDateFormat:@"yyyy-MM-dd HH:mm"];//24格式
return [dateformatter stringFromDate:date1];
}
9,xcode ios 真机调试包和放置的路径, 注: 所有的 (一直更新这个包)
10, 本来是个很简单的需求,因为 UITextField 有secureTextEntry这个属性可以用。但没想到,简单的一句代码并不能解决问题
- (IBAction)secureSwitchAction:(id)sender {
self.passwordTextField.secureTextEntry= !self.passwordInputTextField.secureTextEntry;
}
切换明文/密文显示末尾空白的 bug,
- (IBAction)secureSwitchAction:(id)sender {
self.passwordTextField.secureTextEntry = !self.passwordTextField.secureTextEntry;
NSString* text = self.passwordTextField.text;
self.passwordTextField.text = @" ";
self.passwordTextField.text = text;
}
只用一行代码
[self.passwordInputTextField becomeFirstResponder];
就能解决这个问题,
只是副作用是会让输入焦点切换到密码框。如果不介意的话,用这个方法也可以。
11.Xcode8 log
Product -> Scheme -> Edit Scheme ->run->Argunments-> Environment Varibales 添加字段
OS_ACTIVITY_MODE
并将属性值设置为
disable
12, 数组排序
NSComparatorcmptr = ^(idobj1,idobj2){
if([obj1integerValue] > [obj2integerValue]) {
return(NSComparisonResult)NSOrderedDescending;
}
if([obj1integerValue] < [obj2integerValue]) {
return(NSComparisonResult)NSOrderedAscending;
}
return(NSComparisonResult)NSOrderedSame;
};
self.sortArr= [self.typeArrMsortedArrayUsingComparator:cmptr];
13,【这种用法可以让你指定到你想返回的视图中去】根据上述功能,我将此段代码放在了视图3中
NSArray*pushVCAry = [self.navigationControllerviewControllers];
UIViewController*popVC = [pushVCAry objectAtIndex:pushVCAry.count - 3];
[self.navigationController popToViewController:popVC animated:YES];
14, 禁用滑动返回手势需要在改界面的ViewController中添加如下代码
- (void)viewDidAppear:(BOOL)animated{
[superviewDidAppear:animated];
// 禁用返回手势
if([self.navigationControllerrespondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled=NO;
}
}
如果只是该界面禁用滑动返回手势,还需要添加如下代码使其他界面能够继续使用滑动返回手势:
- (void)viewWillDisappear:(BOOL)animated{
[superviewWillDisappear:animated];
// 开启返回手势
if([self.navigationControllerrespondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled=YES;
}
}
15. cell动画
-(void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath{
if(indexPath.section==1&&self.stuData.count>0) {
[selfstartAnimation:celloffsetY:80duration:1.0];
}
}
-(void)startAnimation:(UIView*)view offsetY:(CGFloat)offsetY duration:(NSTimeInterval)duration{
view.transform=CGAffineTransformMakeTranslation(0, offsetY);
[UIViewanimateWithDuration:durationanimations:^{
view.transform=CGAffineTransformIdentity;
}];
}
16.cell上下左右边距
- (void)setFrame:(CGRect)frame{
//修改cell的左右边距为5;
//修改cell的Y值下移5;
//修改cell的高度减少5;
staticCGFloatmargin =5;
frame.origin.x= margin;
frame.size.width-=2* frame.origin.x;
frame.origin.y+= margin;
frame.size.height-= margin;
[supersetFrame:frame];
}
UIWindow中有相关层级设定的如下设置
typedefCGFloat UIWindowLevel;
constUIWindowLevel UIWindowLevelNormal;// 0.0
constUIWindowLevel UIWindowLevelAlert;// 2000.0
constUIWindowLevel UIWindowLevelStatusBar;// 1000.0
StatusBar的层级是1000 所以只需要将UIWindow层级设置为
UIWindowLevelAlert即可
然后接下来在改变层级的UIWindow中放置View便可以遮挡状态栏的位置了
18
// 重写该方法,就会出现删除按钮
- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath{
// 删除操作的代码块...
}
// 修改删除按钮的名称
- (NSString*)tableView:(UITableView*)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath*)indexPath{
return@"删除";
}
19,label显示带html标签的文字
NSAttributedString*attrStr = [[NSAttributedStringalloc]initWithData:[subHtmlName dataUsingEncoding:NSUnicodeStringEncoding]options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType,
NSFontAttributeName: [UIFontsystemFontOfSize:13]}documentAttributes:nilerror:nil];
self.subTitle.attributedText= attrStr;
2.
NSData*data = [subHtmlNamedataUsingEncoding:NSUnicodeStringEncoding];
NSDictionary*options =@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType};
NSAttributedString*html = [[NSAttributedStringalloc]initWithData:data
options:options
documentAttributes:nil
error:nil];
self.subTitle.attributedText= html;
20,
如果你不控制你使用的图像服务器,你可能无法改变它的内容更新时的网址。这是一种情况下,脸谱网头像网址为例。在这种情况下,你可以使用sdwebimagerefreshcached旗。这将稍微降低性能,但会尊重HTTP缓存控制头
[self.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://127.0.0.1/fly.jpg"] placeholderImage:[UIImage imageNamed:@"404"] options:SDWebImageRefreshCached];
21,html 添加文字颜色,字体
把字符串添加进去:
NSString *htmlString = @"<head><style>body{font-family:arial,Helvetica;font-size:15;color:#000000;word-wrap:break-word;}</style><head>";
22, 时间戳
NSTimeInterval interval= [[NSDate date] timeIntervalSince1970] * 1000;
23, 通过拖动UIWebView来移除键盘
self.webView.scrollView.keyboardDismissMode= UIScrollViewKeyboardDismissModeOnDrag;// 当拖动时移除键盘
24,保存模型到plist中
首先模型遵守NSCoding协议, 实现下面两个方法
- (void)encodeWithCoder:(NSCoder*)aCoder{
[aCoderencodeObject:self.nameforKey:@"name"];
}
- (id)initWithCoder:(NSCoder*)aDecoder{
if(self= [super init]) {
self.name= [aDecoderdecodeObjectForKey:@"name"];
}
return self;
}
保存
[ [NSUserDefaults standardUserDefaults]setObject:[NSKeyedArchiver archivedDataWithRootObject:arrayM] forKey:@"key"];
读取
[NSKeyedUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] objectForKey:@"key"]]
25,设置标签文字过长时的显示方式。
lineBreakMode:设置标签文字过长时的显示方式。
label.lineBreakMode= NSLineBreakByCharWrapping;//以字符为显示单位显示,后面部分省略不显示。
label.lineBreakMode= NSLineBreakByClipping;//剪切与文本宽度相同的内容长度,后半部分被删除。
label.lineBreakMode= NSLineBreakByTruncatingHead;//前面部分文字以……方式省略,显示尾部文字内容。
label.lineBreakMode= NSLineBreakByTruncatingMiddle;//中间的内容以……方式省略,显示头尾的文字内容。
label.lineBreakMode= NSLineBreakByTruncatingTail;//结尾部分的内容以……方式省略,显示头的文字内容。
label.lineBreakMode= NSLineBreakByWordWrapping;//以单词为显示单位显示,后面部分省略不显示。
26, 导航栏显示与隐藏
if(hiden) {
[UIViewanimateWithDuration:0.5animations:^{
CGRectframe =self.navigationController.navigationBar.frame;
frame.origin.y= -64;
self.navigationController.navigationBar.frame= frame;
}completion:^(BOOLfinished) {
[self.navigationController.navigationBarsetHidden:hiden];
}];
}else{
[self.navigationController.navigationBarsetHidden:hiden];
[UIViewanimateWithDuration:0.5animations:^{
CGRectframe =self.navigationController.navigationBar.frame;
frame.origin.y=20;
self.navigationController.navigationBar.frame= frame;
}completion:^(BOOLfinished) {
}];
}
27, 有时候, cellForItemAtIndexPath方法不执行, 而numberOfItemsInSection是正常返回count,
遵循UICollectionViewDelegateFlowLayout
实现下面的方法:
-(CGSize)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath*)indexPath;
这样就可以了.
28, 当TableView 向下偏移的时候, 这样设置
_myTableView.autoresizingMask=UIViewAutoresizingFlexibleHeight;
http://blog.csdn.net/samrtian/article/details/38472285
30, AVAudioPlayer 锁屏界面播放的时候,
点击上下一首, 播放暂停不管用, 这是因为在xcode8中设置了, OS_ACTIVITY_MODE disable
去掉就行了
31, iOS 如何 复制到剪贴板
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = @"你好";
32, [NSStringstringWithFormat:@"%@/Library/Caches/WHCSqlite/",NSHomeDirectory()];
33
视频: http://s.budejie.com/topic/list/jingxuan/41/bs0315-iphone-4.2/0-20.json
http://d.api.budejie.com/topic/list/chuanyue/41/bs0315-iphone-4.2/0-20.json
图片: http://s.budejie.com/topic/list/jingxuan/10/bs0315-iphone-4.2/0-20.json
http://d.api.budejie.com/topic/list/chuanyue/10/bs0315-iphone-4.2/0-20.json
段子: http://s.budejie.com/topic/tag-topic/64/hot/bs0315-iphone-4.2/0-20.json
美女: http://s.budejie.com/topic/tag-topic/117/hot/bs0315-iphone-4.2/0-20.json
声音: http://d.api.budejie.com/topic/list/chuanyue/31/bs0315-iphone-4.2/0-20.json
http://s.budejie.com/topic/list/zuixin/31/bs0315-iphone-4.2/0-20.json
34、UISlider增量/减量为固定值(假如为5)
- (void)setupSlider{
UISlider *slider = [[UISlider alloc] init];
[self.view addSubview:slider];
[slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
slider.maximumValue = 100;
slider.minimumValue = 0;
slider.frame = CGRectMake(200, 20, 100, 30);
}
- (void)sliderAction:(UISlider *)slider{
[slider setValue:((int)((slider.value + 2.5) / 5) * 5) animated:NO];
}
35, 获取随机UUID
NSString *result;
if([[[UIDevice currentDevice] systemVersion] floatValue] > 6.0){
result = [[NSUUID UUID] UUIDString];
}else{
CFUUIDRef uuidRef = CFUUIDCreate(NULL);
CFStringRef uuid = CFUUIDCreateString(NULL, uuidRef);
CFRelease(uuidRef);
result = (__bridge_transfer NSString *)uuid;
}