用到的IOS知识点小结(1)

以下内容是在ios6模拟器运行成功的,或者与我自己的开发环境有关系。     

1.强制转屏,不过不推荐,是私有方法

 

//    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {

//        [[UIDevice currentDevice] performSelector:@selector(setOrientation:)

//                                       withObject:(id)UIDeviceOrientationPortrait];

//    }

 

2.给导航条添加自定义的图片按钮,并且要有点击事件

先建立个按钮:

 

    UIButton *button1 = [UIButtonbuttonWithType:UIButtonTypeCustom];

    [button1 setImage:[UIImageimageNamed:@"btu_shop.png"] forState:UIControlStateNormal];

    [button1 addTarget:selfaction:@selector(gotoShop) forControlEvents:UIControlEventTouchUpInside];

    button1.frame = CGRectMake(0, 0, 60, 40);

然后把按钮作为一个view加入 UIBarButtonItem中:

 

UIBarButtonItem *shopButton = [[UIBarButtonItemalloc]initWithCustomView:button1];

 

self.navigationItem.leftBarButtonItems = [NSArrayarrayWithObjects:shopButton,storeButton, nil];

3.把一张图片作为背景

 

    UIImageView *imageView = [[UIImageViewalloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];

    imageView.image = [UIImageimageNamed:@"background.png"];

    [self.viewinsertSubview:imageView belowSubview:self.table];

4.读取图片,不存在图片则下载

 

- (UIImage *)getPictureWithURL:(NSString *)str {

    

    UIImage *image = nil;

    NSString *picURLWithMD5 = [[Cell class]md5:str];//先把图片的路径加密

    NSString *picPath =  [[Cell class]makeUserFilePath:picURLWithMD5];

    

    if ([[NSFileManagerdefaultManager] fileExistsAtPath:picPath]) {

        //存在图片的时候直接读取

        NSData *data = [NSDatadataWithContentsOfFile:picPath];

        image = [UIImage imageWithData:data];

    }

    else{

        //下载图片

        NSURL *url=[NSURLURLWithString:str];

        image = [[[UIImagealloc] initWithData:[NSDatadataWithContentsOfURL:url]]autorelease];

        

        //将图片写到文件中

        [UIImagePNGRepresentation(image) writeToFile: picPath  atomically:YES];

    }

    return image;

}

5.输入框有字的时候再进行操作

 

  if(self.textField.text.length != 0){

6.想去除一个modalView的同时跳转,必须用:

 

[selfdismissViewControllerAnimated:YEScompletion:^{

        UINavigationController *nav = [[UINavigationControlleralloc] initWithRootViewController:detailView];      

        [selfpresentModalViewController:nav animated:YES];

        [nav release];

    }];

7.sqlite更新自增值

 

//    char *update = "update sqlite_sequence set seq = 0 ";//更新自增的值

//    sqlite3_prepare_v2(database, update , -1, &statement, nil) ;

//    if (sqlite3_step(statement) != SQLITE_DONE)

//    {

//        NSLog(@"error update!");

//    }

8.把UIView转成Image,导入<QuartzCore/QuartzCore.h>

 

-(UIImage *)makeScreenshot:(UIView*) tView{

    [tView retain];

    @try {

        if(UIGraphicsBeginImageContextWithOptions != NULL)

        {

            UIGraphicsBeginImageContextWithOptions(tView.bounds.size, NO, 1);

        } else {

            UIGraphicsBeginImageContext(tView.bounds.size);

        }

    }

    @catch (NSException *exception) {

        [tView release];

        return nil;

    }

    

    [tView.layerrenderInContext:UIGraphicsGetCurrentContext()];

UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

[tView release];

return viewImage;

}

 


 










 


 

posted @ 2013-07-11 18:34  爱生活,爱编程  阅读(205)  评论(0编辑  收藏  举报