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证书目录

posted @ 2013-07-05 14:37  Clin  阅读(570)  评论(1编辑  收藏  举报