美文网首页
QQ登录界面头像选择代码

QQ登录界面头像选择代码

作者: 染小沫 | 来源:发表于2016-07-13 19:39 被阅读0次

    //

    //  ViewController.m

    //  fangwenxitongxiangce

    //

    //  Created by lanou on 16/7/12.

    //  Copyright © 2016年lanou. All rights reserved.

    //

    #import"ViewController.h"

    @interfaceViewController()

    @property(nonatomic,strong)UIButton*userBtn;

    @end

    @implementationViewController

    - (void)viewDidLoad {

    [superviewDidLoad];

    //所有的能看到的ui控件创建初始化方式都可以采用alloc initWithFrame

    self.userBtn= [[UIButtonalloc]initWithFrame:CGRectMake(150,80,100,100)];

    //设置颜色

    self.userBtn.backgroundColor= [UIColorredColor];

    //设置圆弧半径

    self.userBtn.layer.cornerRadius=50;

    //

    self.userBtn.layer.masksToBounds=YES;

    //添加点击事件:去访问系统相册

    [self.userBtnaddTarget:selfaction:@selector(setUserImage)forControlEvents:(UIControlEventTouchUpInside)];

    //将按钮添加到屏幕上面来

    [self.viewaddSubview:self.userBtn];

    }

    //

    -(void)setUserImage

    {

    //创建系统相册

    UIImagePickerController*imagePicker = [[UIImagePickerControlleralloc]init];

    //设置代理

    imagePicker.delegate=self;

    //弹出系统相册

    [selfpresentViewController:imagePickeranimated:YEScompletion:nil];

    }

    - (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

    }

    //这个方法是协议UIImage里面的,选择图片结束的时候就会自动调用

    - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingImage:(UIImage*)image editingInfo:(nullableNSDictionary *)editingInfo

    {

    //设置头像

    [self.userBtnsetBackgroundImage:imageforState:(UIControlStateNormal)];

    //将系统相册消失掉

    [pickerdismissViewControllerAnimated:YEScompletion:nil];

    }

    @end

    相关文章

      网友评论

          本文标题:QQ登录界面头像选择代码

          本文链接:https://www.haomeiwen.com/subject/rofejttx.html