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

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

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

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

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

//                                       withObject:(id)UIDeviceOrientationPortrait];

//    }


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

先建立个按钮:

    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];

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

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

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

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

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

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

3.把一张图片作为背景

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

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

    [self.view insertSubview: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 ([[NSFileManager defaultManager] fileExistsAtPath:picPath]) {

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

        NSData *data = [NSData dataWithContentsOfFile:picPath];

        image = [UIImage imageWithData:data];

    }

    else{

        //下载图片

        NSURL *url=[NSURL URLWithString:str];

        image = [[[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:url]]autorelease];

        

        //将图片写到文件中

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

    }

    return image;

}

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

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

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

[self dismissViewControllerAnimated:YES completion:^{

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

        [self presentModalViewController: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.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

[tView release];

return viewImage;

}















  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值