zoukankan      html  css  js  c++  java
  • iOS 从手机相册里选取图片

    #import <UIKit/UIKit.h>
    
    @interface AppDelegate : UIResponder <UIApplicationDelegate>
    
    @property (strong, nonatomic) UIWindow *window;
    
    
    @end
    #import "AppDelegate.h"
    #import "RootViewController.h"
    @interface AppDelegate ()
    
    @end
    
    @implementation AppDelegate
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.window.backgroundColor = [UIColor whiteColor];
        
        UINavigationController *root = [[UINavigationController alloc] initWithRootViewController:[[RootViewController alloc] init]];
        self.window.rootViewController = root;
        
        
        [self.window makeKeyAndVisible];
        return YES;
    }
    
    @end
    #import <UIKit/UIKit.h>
    
    @interface RootViewController : UIViewController
    
    @end
    #import "RootViewController.h"
    
    @interface RootViewController ()<UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>
    
    @property (strong, nonatomic) UIButton *btn;
    
    @end
    
    @implementation RootViewController
    
    @synthesize btn;
    
    - (void)loadView
    {
        [super loadView];
        btn= [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(100, 100, 150, 80);
        btn.backgroundColor = [UIColor purpleColor];
        [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:btn];
    }
    
    - (void)btnAction:(UIButton *)sender
    {
        UIActionSheet *actionsheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从手机相册选取", nil];
        [actionsheet showInView:self.view];
    }
    
    - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        if (buttonIndex == 0) {
            UIImagePickerController *imagepicker = [[UIImagePickerController alloc] init];
            imagepicker.delegate = self;
            imagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            imagepicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
            imagepicker.allowsEditing = YES;
            [self presentViewController:imagepicker animated:YES completion:^{}];
        }
    }
    
    #pragma amrk - 图片选择完成 - 
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
    {
        [picker dismissViewControllerAnimated:YES completion:^{
            [btn setImage:image forState:0];
        }];
    }
    
    @end
  • 相关阅读:
    Cocos2d-x win7下 android环境搭建
    cocos2dx 环境搭建 win7 +vs2012+ cocos2dx-2.1.4
    IOS 通过界面图标启动Web应用 + 全屏应用 + 添加到主屏幕
    js 魔鬼训练
    远程调试 Weinre
    PHP uniqid 高并发生成不重复唯一ID
    html5 炫酷的字幕雨
    学习建模
    jquery 购物车飞入效果
    jquery/zepto 圣诞节雪花飞扬
  • 原文地址:https://www.cnblogs.com/lantu1989/p/4928039.html
Copyright © 2011-2022 走看看