使用OS的系统,在使用OC语言的基础上创建访问系统相册,就是创建其他应用程序的部分语句,也就是在苹果系统上QQ的登录系统的一部分。
#import"ViewController.h"
//遵守协议
@interfaceViewController()
@property(nonatomic,strong)UIButton*userBtu;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
//所有的能看得到的UI控件创建初始化方式都可以采用allocinitWithFrame
self.userBtu= [[UIButtonalloc]initWithFrame:CGRectMake(30,60,80,80)];
//设置颜色
self.userBtu.backgroundColor= [UIColorredColor];
//将图片加载到内存中
UIImage*image = [UIImageimageNamed:@"login_header"];
//将加到内存后的图片设置为背景图片
[self.userBtusetBackgroundImage:imageforState:(UIControlStateNormal)];
//设置圆形半径
self.userBtu.layer.cornerRadius=40;
//超过内切圆的图片给切割掉
self.userBtu.layer.masksToBounds=YES;
//添加点击事件:去访问系统相册
[self.userBtuaddTarget:selfaction:@selector(setUserImage)forControlEvents:(UIControlEventTouchUpInside)];
//将按钮添加到屏幕上面来
[self.viewaddSubview:self.userBtu];
}
//访问系统相册
-(void)setUserImage
{
UIImagePickerController*imagePicker = [[UIImagePickerControlleralloc]init];
//设置代理,到@interface后面
UIImagePickerControllerDelegate>
imagePicker.delegate=self;
//弹出相册
[selfpresentViewController:imagePickeranimated:YEScompletion:nil];
}
//这个方法是协议UIImagePickerControllerDelegate里面的,选择图片结束的时候就会自动调用
- (void)imagePickerController:(UIImagePickerController*)picker
didFinishPickingImage:(UIImage*)image editingInfo:(nullableNSDictionary *)editingInfo
{
//设置头像
[self.userBtusetBackgroundImage:imageforState:(UIControlStateNormal)];
//将系统相册消失掉
[pickerdismissViewControllerAnimated:YEScompletion:nil];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any
resources that can be recreated.
}
@end