#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:需要修改圆形图标
_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设置边框
- (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协议方法
-(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-图片选择协议方法
-(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 - 服务器长传图片的方法,注意是群组图片
-(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];
}
设置图片选择器
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 示例: 获取属性 - attr() jQuery attr() 方法用于获取属性值。 //获取属性值 1 JQUE...