打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
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 = [UIImagePickerControllerisCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront];

    

    if (result) {


        UIImagePickerController *imgPickerCtrl = [[UIImagePickerControlleralloc] init];

        imgPickerCtrl.delegate = self;

        

        //源类型, 相机

        imgPickerCtrl.sourceType =UIImagePickerControllerSourceTypeCamera;

        //设置为前置摄像头

        imgPickerCtrl.cameraDevice =UIImagePickerControllerCameraDeviceFront;

        

        [selfpresentViewController:imgPickerCtrl animated:YEScompletion:^{

            

        }];

        

        [imgPickerCtrl release];

    }else{

        UIAlertView *alertView = [[UIAlertViewalloc] initWithTitle:nilmessage:@"您的设备没有摄像头" delegate:selfcancelButtonTitle: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(@"保存图片成功");

    }

}





本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
iphone 自定义uipickerview
详解iOS开发中UIPickerView控件的使用方法
iOS开发之iOS程序偏好设置(Settings Bundle)的使用
IOS
iOS inputView 和 inputAccessoryView
自定义PickView,一行代码即可搞定选择器!
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服