PickerView常用方法


// 与表视图相同,设置picker数据

@property(nonatomic,assign) id<UIPickerViewDataSource> dataSource;

// 与表视图相同,component(组件)宽度 以及行高度  设置picker外观 回调

@property(nonatomic,assign) id<UIPickerViewDelegate>   delegate;

// 显示一个picker视图当前指向的位置指示

@property(nonatomic)        BOOL                       showsSelectionIndicator;   // default is NO


// 一个picker视图有多少个组件

@property(nonatomic,readonly) NSInteger numberOfComponents;

// 一个组件有多少个行

- (NSInteger)numberOfRowsInComponent:(NSInteger)component;

// 返回picker视图其中一个组件的宽和高

- (CGSize)rowSizeForComponent:(NSInteger)component;

// 返回picker视图中自定义视图

- (UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component;

// 重新加载所有组件内容

- (void)reloadAllComponents;

// 根据指定的组件,刷新组件中的数据

- (void)reloadComponent:(NSInteger)component;

// 制定picker视图的起始位置

- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated;  // scrolls the specified row to center.

// 返回组件当前选中的行

- (NSInteger)selectedRowInComponent:(NSInteger)component;                                   // returns selected row. -1 if nothing selected


@end



@protocol UIPickerViewDataSource<NSObject>

@required


// 返回picker视图中有几个组件 类似与表视图数据源方法

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;


// 返回组件的行数

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;

@end



@protocol UIPickerViewDelegate<NSObject>

@optional


// 设置picker视图中 组件的宽度

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component;

// 组件行的高度

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component;


// 设置组件的内容

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;

// 自定义的时候需要调用这个方法

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;


/*以上两个设置内容方法是相互的排斥*/


// 回调函数

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;


//1.判断设备是否有前置摄像头. UIImagePickerControllerCameraDeviceRear 后置摄像头,还有一个是front是前置摄像头

    BOOL result = [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront];

    

    if (result) {


        UIImagePickerController *imgPickerCtrl = [[UIImagePickerController alloc] init];

        imgPickerCtrl.delegate = self;

        

        //源类型, 相机

        imgPickerCtrl.sourceType = UIImagePickerControllerSourceTypeCamera;

        //设置为前置摄像头

        imgPickerCtrl.cameraDevice = UIImagePickerControllerCameraDeviceFront;

        

        [self presentViewController:imgPickerCtrl animated:YES completion:^{

            

        }];

        

        [imgPickerCtrl release];

    }else{

        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"您的设备没有摄像头" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];

        [alertView show];

        [alertView release];

    }



----系统奇葩问题。保存图片

 UIImage *img = [UIImage imageWithData:data];

   

  //把图片保存到相册

  UIImageWriteToSavedPhotosAlbum(img, self@selector(image:didFninishError:info:), NULL);


#pragma mark -

- (void)image:(UIImage *)image didFninishError:(NSError *)error info:(void *)contextInfo

{

    if (!error) {

        

        NSLog(@"保存图片成功");

    }

}





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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值