A. ios 怎么修改相册界面navigationitem显示
ios修改相册界面navigationitem显示是通过uiviewcontroller添加的navigationbar展示的。具体代码如下:
//创建homeButtonView层
UIView *homeButtonView = [[[UIView alloc]initWithFrame:CGRectMake(0, 0, 55, 40)]autorelease];
UIImageView *homeButtonImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 55, 40)];
homeButtonImageView.image = [UIImage imageNamed:@"nav_btn_home_ipad.png"];
UIButton *homeButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 55, 40)];
homeButton.backgroundColor = [UIColor clearColor];
[homeButton addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
[homeButtonView addSubview:homeButtonImageView];
[homeButtonView addSubview:homeButton];
[homeButton release];
[homeButtonImageView release];
//创建home按钮
UIBarButtonItem *homeButtonItem = [[UIBarButtonItem alloc]initWithCustomView:homeButtonView];
self.navigationItem.leftBarButtonItem=homeButtonItem;
[homeButtonItem release];
B. ios用asi怎么上传系统相册照片
1.新建一个single view工程,导入ASIHttpRequest库,导入MobileCoreServices、CFNetwork、SystemConfiguration和libz1.2.5.dylib四个系统库
2.随便导入一张图片,比如haoyou.png
3.ViewController.h
#import <uikit uikit.h="">
#import "ASIHTTPRequest.h"
#import "ASIFormDataRequest.h"
@interface ViewController : UIViewController
@property (nonatomic, )NSString *m_auth;
@end</asihttprequestdelegate></uikit>
4.ViewController.m 添加两个按钮
(void)viewDidLoad {
[super viewDidLoad];
UIButton *loginBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
loginBtn.frame = CGRectMake(100, 20, 120, 40);
[loginBtn setTitle:@"登录" forState:UIControlStateNormal];
[loginBtn addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:loginBtn];
UIButton *uploadBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
uploadBtn.frame = CGRectMake(100, 80, 120, 40);
[uploadBtn setTitle:@"上传" forState:UIControlStateNormal];
[uploadBtn addTarget:self action:@selector(upload) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:uploadBtn];
}
5.实现login和upload两个方法
- (void)login {
NSURL *url = [NSURL URLWithString:@"..."];//此处省略请求url
//请求
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
request.tag = 10;
request.delegate = self;
[request startAsynchronous];
}
- (void)upload {
NSURL* url = [NSURL URLWithString:@"..."];//此处省略请求url
UIImage* img = [UIImage imageNamed:@"haoyou.png"];
NSData* data = UIImagePNGRepresentation(img);
//ASIFormDataRequest请求是post请求,可以查看其源码
ASIFormDataRequest* request = [ASIFormDataRequest requestWithURL:url];
request.tag = 20;
request.delegate = self;
[request setPostValue:self.m_auth forKey:@"m_auth"];
// [request setFile:@"tabbar.png" forKey:@"haoyou"];//如果有路径,上传文件
[request setData:data withFileName:@"tmp.png" andContentType:@"image/png" forKey:@"headimage"];
// 数据 文件名,随便起 文件类型 设置key
[request startAsynchronous];
}
6.实现协议
- (void)requestFailed:(ASIHTTPRequest *)request {
NSLog(@"请求失败");
}
- (void)requestFinished:(ASIHTTPRequest *)request {
if (request.tag == 10) {
NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:request.responseData options:0 error:nil];
self.m_auth = [dic objectForKey:@"m_auth"];
NSLog(@"%@", self.m_auth);
}
if (request.tag == 20) {
NSLog(@"%@", request.responseString);
}
}
C. ios 点击按钮后怎么访问本地相册
创建工程项目和视图控制器
创建一个single view工程项目,自动创建一个ViewController试图控制器。
创建并初始化UI控件
在ViewController.m创建并初始化UIImageView用于显示获取的图片,UIButton及响应事件。
设置宏定义、添加代理
判断是否是iOS8以上版本系统:
#define IOS8 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0 ? YES : NO)
调用相册需要使用:
,代理,iOS7使用UIActionSheet需要添加UIActionSheetDelegate。
完善按钮响应事件
iOS8使用UIAlertController选择获取图片方式;
iOS8使用UIAlertAction选择获取图片方式。
添加自定义方法保存图片到本地沙盒
选择完成后调用。
获取图片缓存并显示
完成示例
要允许app调用相机,读取相册图片。