設(shè)置圖片選擇器

#import "AFHttpManager.h"
@interface EditGroupInfoViewController () <UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>

/**
 跑團名稱
 */
@property (weak, nonatomic) IBOutlet UITextView *groupNameTextView;

/**
 跑團城市
 */
@property (weak, nonatomic) IBOutlet UITextView *groupCityTextView;

/**
 跑團頭像
 */
@property (weak, nonatomic) IBOutlet UIImageView *groupImageView;
/**
 跑團宣言
 */
@property (weak, nonatomic) IBOutlet UITextView *groupManifestoTextView;

@end

@implementation EditGroupInfoViewController
{
    NSData *imageData;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    DLog(@"編輯跑團界面");
//    self.title = @"編輯跑團";
    self.navigationController.title = @"編輯跑團";
    //MARK:需要修改圓形圖標(biāo)
    _groupImageView.layer.cornerRadius = _groupImageView.bounds.size.width/2;
    _groupImageView.layer.masksToBounds = YES;
    [self changeTextView:self.groupCityTextView];
    [self changeTextView:self.groupNameTextView];
    [self changeTextView:self.groupManifestoTextView];
    
    
}

#pragma mark - textView設(shè)置邊框
- (void)changeTextView:(UITextView *)textView {
    textView.layer.borderColor = [[UIColor colorWithRed:215.0 / 255.0 green:215.0 / 255.0 blue:215.0 / 255.0 alpha:1] CGColor];
    textView.layer.borderWidth = 0.6f;
    textView.layer.cornerRadius = 6.0f;
}
- (IBAction)upIamgeViewAction:(id)sender {
    DLog(@"上傳頭像");
    
    UIActionSheet *myActionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:CustomLocalizedString(@"OpenCamera", nil),CustomLocalizedString(@"AlbumSelection",nil), nil];
    [myActionSheet showInView:self.view];
}
#pragma mark-actionSheet協(xié)議方法
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == actionSheet.cancelButtonIndex) {
        NSLog(@"取消");
    }
    
    switch (buttonIndex) {
        case 0:
        {
            //打開相機
            [self takePhoto];
        }
            break;
        case 1:
        {
            //打開相冊
            [self openPhoto];
        }
            break;
        default:
            break;
    }
    
}
//打開相機
-(void)takePhoto{
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        UIImagePickerController *picker = [[UIImagePickerController alloc]init];
        picker.delegate = self;
        picker.allowsEditing = YES;
        picker.sourceType = sourceType;
        [self presentViewController:picker animated:YES completion:nil];
    }else{
        NSLog(@"模擬器無法打開照相機涡戳,請在真機中使用");
    }
}
//打開相冊
-(void)openPhoto{
    UIImagePickerController *picker = [[UIImagePickerController alloc]init];
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
    picker.allowsEditing = YES;
    [self presentViewController:picker animated:YES completion:nil];
}
#pragma mark-圖片選擇協(xié)議方法
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
    UIImage *image;
    if ([type isEqualToString:@"public.image"]) {
        image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
        NSData *data = [NSData data];
        
        
        if (UIImagePNGRepresentation(image)==nil) {
            data = UIImageJPEGRepresentation(image, 0.1);
            imageData = data;
        }else{
            data = UIImagePNGRepresentation(image);
            imageData = data;
            
        }
        //MARK:這里要修改為上傳群組的頭像
//        [self requestimagedata];
        
        
        
        //將剪裁后的圖片放到ImageView上
        [picker dismissViewControllerAnimated:YES completion:^{
           
            self.groupImageView.image = image;            _groupImageView.clipsToBounds = YES;
        }];
    }else{
        [picker dismissViewControllerAnimated:YES completion:^{
            NSLog(@"上傳頭像失敗");
        }];
    }
    
}
#pragma mark - 服務(wù)器長傳圖片的方法,注意是群組圖片
-(void)requestimagedata
{
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:[ToolUtils readToken] forKey:@"token"];
    [dic setValue:@"6" forKey:@"type"];
    
    //MainUrl(@"/service/show/serviceInfoByWhere")
    [AFHttpManager postUploadWithUrl:MainUrl(@"/users/login/uploadPic") fileUrl:imageData parameter:dic success:^(id responseObject) {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:[NSString stringWithFormat:@"%@UserListbool" ,[[NSUserDefaults standardUserDefaults] objectForKey:@"identifySaves"]]];
        [[NSUserDefaults standardUserDefaults] synchronize];
    } failure:^(NSError *error) {
        
    }];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - 完成
- (IBAction)didAccomplishAction:(id)sender {
    DLog(@"點擊完成按鈕");
    [self.navigationController popViewControllerAnimated:YES];
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末赦颇,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子硬耍,更是在濱河造成了極大的恐慌匿值,老刑警劉巖赠制,帶你破解...
    沈念sama閱讀 218,525評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異挟憔,居然都是意外死亡钟些,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,203評論 3 395
  • 文/潘曉璐 我一進店門绊谭,熙熙樓的掌柜王于貴愁眉苦臉地迎上來政恍,“玉大人,你說我怎么就攤上這事达传「Ю” “怎么了?”我有些...
    開封第一講書人閱讀 164,862評論 0 354
  • 文/不壞的土叔 我叫張陵趟大,是天一觀的道長鹤树。 經(jīng)常有香客問我,道長逊朽,這世上最難降的妖魔是什么罕伯? 我笑而不...
    開封第一講書人閱讀 58,728評論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮叽讳,結(jié)果婚禮上追他,老公的妹妹穿的比我還像新娘。我一直安慰自己岛蚤,他們只是感情好邑狸,可當(dāng)我...
    茶點故事閱讀 67,743評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著涤妒,像睡著了一般单雾。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,590評論 1 305
  • 那天硅堆,我揣著相機與錄音屿储,去河邊找鬼。 笑死渐逃,一個胖子當(dāng)著我的面吹牛够掠,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播茄菊,決...
    沈念sama閱讀 40,330評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼疯潭,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了面殖?” 一聲冷哼從身側(cè)響起竖哩,我...
    開封第一講書人閱讀 39,244評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎畜普,沒想到半個月后期丰,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,693評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡吃挑,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,885評論 3 336
  • 正文 我和宋清朗相戀三年钝荡,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片舶衬。...
    茶點故事閱讀 40,001評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡埠通,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出逛犹,到底是詐尸還是另有隱情端辱,我是刑警寧澤,帶...
    沈念sama閱讀 35,723評論 5 346
  • 正文 年R本政府宣布虽画,位于F島的核電站舞蔽,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏码撰。R本人自食惡果不足惜渗柿,卻給世界環(huán)境...
    茶點故事閱讀 41,343評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望脖岛。 院中可真熱鬧朵栖,春花似錦、人聲如沸柴梆。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,919評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽绍在。三九已至门扇,卻和暖如春雹有,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背悯嗓。 一陣腳步聲響...
    開封第一講書人閱讀 33,042評論 1 270
  • 我被黑心中介騙來泰國打工件舵, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留卸察,地道東北人脯厨。 一個月前我還...
    沈念sama閱讀 48,191評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像坑质,于是被迫代替她去往敵國和親合武。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,955評論 2 355

推薦閱讀更多精彩內(nèi)容