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調用相機,讀取相冊圖片。