iphone开发笔记
1.uiimage圖片拉伸
- (void)stretchBackgroundImage {//UIImage *originalImage = [[self backgroundImageForState:UIControlStateNormal] copy];UIImage *originalImage = [UIImage imageNamed:@"sure_publish_green.png"];//UIEdgeInsets insets = UIEdgeInsetsMake(2, 10, 2, 10);//UIImage *stretchableImage = [originalImage resizableImageWithCapInsets:insets];UIImage *stretchableImage = [originalImage stretchableImageWithLeftCapWidth:15 topCapHeight:12];[self setBackgroundImage:stretchableImage forState:UIControlStateNormal]; }?2.willmovetosupreview
http://iloss.me/blog/2013/05/28/ios6-willmovetosuperview/
3.size to fit 快捷鍵 ?cmd + =
4.nsstring to nsdate
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"yyyy-MM-dd"]; NSDate *date = [dateFormatter dateFromString:publicationDate ]; [dateFormatter release];?5.reloaddata scrollto
- (void)tableView:(UITableView *)theTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {[theTableView deselectRowAtIndexPath:indexPath animated:NO];if (itemType == ItemTypeMore) //更多選項 {[theTableView reloadData];[theTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];} }?6.uiview animation
[UIView animateWithDuration:0.3 animations:^{edit.frame = editFrame;}];?7./BaiduMobStat/lib/Release$(EFFECTIVE_PLATFORM_NAME)
EFFECTIVE_PLATFORM_NAME ?識別真機iphoneos ?模擬器?iphonesimulator
Release-iphoneos
Release-iphonesimulator
8.objective-c語法糖?http://blog.devtang.com/blog/2012/08/05/use-modern-objective-c/
9.ARC和非ARC混編
在非ARC環境下,如果想對某個文件單獨進行ARC處理,則在Build Parses里的.m文件后加-fobjc-arc,反之則加-fno-objc-arc
10.圖片壓縮http://www.open-open.com/lib/view/open1375933073921.html
11.cell取消選中狀態[tableView deselectRowAtIndexPath:indexPath animated:YES];
12.cell不能選中cell.selectionStyle = UITableViewCellSelectionStyleNone ?創建cell的時候設置這個
13.圓角設置
m_mainImgView.layer.cornerRadius = 6;
m_mainImgView.layer.masksToBounds = YES;
14.demo學習http://www.ioslearner.com/uiappearance-proxy-protocol-tutorial/
15.navigationBar add searchBar
To put searchBar into the center of navigationBar:
self.navigationItem.titleView = self.searchBarTop;
-------
To put searchBar to the left/right side of navigationBar:
UIBarButtonItem *searchBarItem = [[UIBarButtonItem alloc] initWithCustomView:searchBar];
self.navigationItem.rightBarButtonItem = searchBarItem;
16.((UILabel*)[[testAlert subviews] objectAtIndex:1]).textAlignment =UITextAlignmentLeft; UIAlertView 居中
17.http://webfrogs.me/2013/04/22/build-cocoapods-project/ ?CocoaPods 第三方類庫管理學習
18.mutiple line text of uilabel ?http://stackoverflow.com/questions/990221/multiple-lines-of-text-in-uilabel
?found a solution.
One just has to add the following code:
textLabel.lineBreakMode =NSLineBreakByWordWrapping; textLabel.numberOfLines =0;Restored old answer (for reference and devs willing to support iOS below 6.0):
textLabel.lineBreakMode =UILineBreakModeWordWrap;
textLabel.numberOfLines =0;
19.label 關鍵字標記成紅色
NSString *text = @"其實沒什么";NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:text];[attributeString setAttributes:@{NSForegroundColorAttributeName : [UIColor redColor], NSFontAttributeName : [UIFont systemFontOfSize:17]} range:NSMakeRange(2, 1)];myLabel.attributedText = attributeString;?20.UIButton上image和title的位置調整方法:
//UIEdgeInsetsMake(top left bottom right) [button setImageEdgeInsets:UIEdgeInsetsMake(0.0, 100.0, 0.0, 0.0)]; //將image的位置向右移動100個像素 [button setTitleEdgeInsets:UIEdgeInsetsMake(0.0 , 100.0, 0.0 , 0.0)]; ////將title的位置向右移動100個像素//UIEdgeInsetsMake原型 UIKIT_STATIC_INLINE UIEdgeInsets UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right) {UIEdgeInsets insets = {top, left, bottom, right};return insets; }21.http://www.cocoachina.com/applenews/devnews/2013/0827/6876.html
22.轉義% ?%%
23.隱藏系統狀態欄 讓app啟動時圖片全屏 進入程序后顯示狀態欄方法。 ?
1)在<APP>-info.list文件中,加上“Status bar is initially hidden”選項,選擇yes
2)在程序里面添加 [[UIApplication sharedApplication]setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
即可?
24.CGFloat fontHeight = [@"string" sizeWithFont:[UIFont fontWithName:@"HelveticaNeue" size:15.0f]].height; 取字體高度
25.xcode正則替換
@synthesize\s(\w+)
copy.\1 = [\1 copyWithZone:zone] ?
26.label多行left-top對齊
CGRect frame = cell.contentLabel.frame; cell.contentLabel.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, 120); cell.contentLabel.lineBreakMode = NSLineBreakByWordWrapping; cell.contentLabel.numberOfLines = 0; cell.contentLabel.text = @"李先生李先生李先生李先生李先生李先生李先生李先生"; [cell.contentLabelsizeToFit];?27.通過UITableViewCell獲得cell在table中信息
UITableView* table = (UITableView *)[cell superview]; NSIndexPath* pathOfTheCell = [table indexPathForCell:cell]; NSInteger sectionOfTheCell = [pathOfTheCell section]; NSInteger rowOfTheCell = [pathOfTheCell row];28.順序動畫執行
[UIView animateWithDuration:0.7 //速度0.7秒animations:^{//修改rView坐標//animate 1 }completion:^(BOOL finished){[UIView animateWithDuration:0.7 //速度0.7秒animations:^{//修改rView坐標//animate 2}completion:^(BOOL finished){}]; }];29.讓UIButton中圖片位置偏移
[myButton setImage: [UIImage imageNamed:@"settingImage.png"] forState:UIControlStateNormal];
[myButton setImageEdgeInsets:UIEdgeInsetsMake(0.0, 100.0, 0.0, 0.0)]; //將image的位置向右移動100個像素
30.格式化輸出時間
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:kCFDateFormatterShortStyle];
[formatter setTimeStyle:kCFDateFormatterShortStyle];
formatter.dateFormat = @"HH:mm a";
NSLog(@"date : %@", [formatter stringFromDate:date]);
30.點擊UIButton縮小動畫
// Scale up on button press - (void) buttonPress:(UIButton*)button {button.transform = CGAffineTransformMakeScale(1.1, 1.1);// Do something else }// Scale down on button release - (void) buttonRelease:(UIButton*)button {button.transform = CGAffineTransformMakeScale(1.0, 1.0);// Do something else }[btn addTarget:self action:@selector(buttonPress:) forControlEvents:UIControlEventTouchDown]; [btn addTarget:self action:@selector(buttonRelease:) forControlEvents:UIControlEventTouchUpInside]; [btn addTarget:self action:@selector(buttonRelease:) forControlEvents:UIControlEventTouchUpOutside]; [btn addTarget:self action:@selector(buttonRelease:) forControlEvents:UIControlEventTouchCancel]; [btn addTarget:self action:@selector(buttonRelease:) forControlEvents:UIControlEventTouchDragExit];31.刪除tableviewcell時,應該先刪除數據源里的數據后,再用deleteRowsAtIndexPaths刪除tableview的行
for (int i = 0; i < count; i++){IHaveSeenCarInfoItem *deleteObject = [deleteObjectArray objectAtIndex:i];int deleteDbId = deleteObject.carInfo.dbId;CarDetailInfoDao *carDao = [CarDetailInfoDao sharedCarDetailInfoDao];if (curSelectFilter_ == IHaveSeenFilterTypeCollect){[carDao deleteCollectRecord:deleteDbId];}else if (curSelectFilter_ == IHaveSeenFilterTypeContactRecord){[carDao deleteContactRecord:deleteDbId];}else if (curSelectFilter_ == IHaveSeenFilterTypeBrowseRecord){[carDao deleteBrowseRecord:deleteDbId];}[carInfoArray removeObject:deleteObject];}[self.carInfoTableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];?32.圖片壓縮
NSData *imageData = UIImageJPEGRepresentation(image, 0.5);//壓縮比例
33.前50條記錄
- (NSMutableArray *)getRecordArray:(CarDetailInfoType)type {NSMutableArray *recordArray = [[NSMutableArray alloc] init];NSString *tableName = tableNameArray_[type];FMDatabase *db = [DBUtils openDB];NSString *sql = [[NSString alloc] initWithFormat:@"SELECT * FROM %@ ORDER BY db_id DESC LIMIT 50", tableName];FMResultSet *rs = [db executeQuery:sql];while ([rs next]){CarDetailInfo *carDetailInfo = [[CarDetailInfo alloc] init];carDetailInfo.dbId = [rs intForColumn:@"db_id"];[recordArray addObject:carDetailInfo];}return recordArray; }?34.~/Library/MobileDevice/Provisioning Profiles? ? ?xcode5證書目錄
轉載于:https://www.cnblogs.com/Clin/p/3173654.html
總結
以上是生活随笔為你收集整理的iphone开发笔记的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 我的安装过程
- 下一篇: FreeRTOS 中断优先级嵌套错误引发