QQ登录界面(一)访问iPhone系统相册并更改图像

//
//  ViewController.m
//  访问系统相册
//
//  Created by Adonis 16/7/12.
//  Copyright © 2016年 LESSON 2. All rights reserved.
//

#import "ViewController.h"
//     遵守代理协议
@interface ViewController ()<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
//   intterface后定义属性
@property(nonatomic,strong)UIButton *userBtn;



@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//  所有的可见控件创建初始化方式都可以采用alloc initWithFrame
    self.userBtn = [[UIButton alloc] initWithFrame:CGRectMake(150, 60, 120, 120)];
//    设置控件颜色
//   self.userBtn.backgroundColor = [UIColor blackColor];
//    导入初始企鹅图片
    UIImage *image = [UIImage imageNamed:@"企鹅图片"];
//    将图片设置为userbtn初始界面
    [self.userBtn setBackgroundImage:image forState:(UIControlStateNormal)];

//    设置圆形半径
    self.userBtn.layer.cornerRadius = 60;
//    将正方形与圆形重合部分切割掉
    self.userBtn.layer.masksToBounds = YES;
//    添加点击事件 去访问系统相册(setUserImage)
    [self.userBtn addTarget:self action:@selector(setUserImage) forControlEvents:(UIControlEventTouchUpInside)];
//    添加到测试窗口

    [self.view addSubview:self.userBtn];



}
//访问系统相册
-(void)setUserImage
{
//    UIImagePickerController 图片选择控制器 访问相册和相机
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
//    设置代理,进delegate到@interface ViewController ()后遵守协议 加上<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
    imagePicker.delegate = self;
//    相片弹出
    [self presentViewController:imagePicker animated:YES completion:nil];

}
//   这个方法是UIImagePickerControllerDelegate协议中的,选择图片结束时就会自动调用图片
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(nullable NSDictionary<NSString *,id> *)editingInfo
{
//    设置头像
    [self.userBtn setBackgroundImage:image forState:(UIControlStateNormal)];
//    收回系统相册 YES 为布尔型 需要过渡动画 nil为消失后无新事件
    [picker dismissViewControllerAnimated:YES completion:nil];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值