//
//ViewController.m
//訪問系統(tǒng)相冊(cè)
//
//Created by lanou on 16/7/12.
//Copyright ? 2016年cmcc. All rights reserved.
//
#import"ViewController.h"
//遵守協(xié)議
@interfaceViewController()
@property(nonatomic,strong)UIButton*userBtn;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
//所以的能看得到的UI控件創(chuàng)建初始化方式都可采用alloc iniwithFrame
self.userBtn= [[UIButtonalloc]initWithFrame:CGRectMake(30,60,80,80)];
//設(shè)置顏色
self.userBtn.backgroundColor= [UIColorredColor];
//設(shè)置圓形半徑
self.userBtn.layer.cornerRadius=40;
self.userBtn.layer.masksToBounds=YES;
//添加點(diǎn)擊事件:去訪問系統(tǒng)相冊(cè)
[self.userBtnaddTarget:selfaction:@selector(setUserImage)forControlEvents:(UIControlEventTouchUpInside)];
//將按鈕添加到屏幕上面
[self.viewaddSubview:self.userBtn];
}
//創(chuàng)建系統(tǒng)相冊(cè)
-(void)setUserImage
{UIImagePickerController*imagePicker = [[UIImagePickerControlleralloc]init];
//設(shè)置代理
imagePicker.delegate=self;
//彈出系統(tǒng)相冊(cè)
[selfpresentViewController:imagePickeranimated:YEScompletion:nil];
}
- (void)imagePickerController:(UIImagePickerController*)picker
didFinishPickingImage:(UIImage*)image editingInfo:(nullableNSDictionary *)editingInfo
{
//設(shè)置頭像
[self.userBtnsetBackgroundImage:imageforState:(UIControlStateNormal)];
//將系統(tǒng)相冊(cè)消失
[picker
dismissViewControllerAnimated:YEScompletion:nil];
}
- (void)didReceiveMemoryWarning{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be
recreated.
}
@end
??????4A