#import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
[self.window makeKeyAndVisible];
UINavigationController* nav = [[UINavigationController alloc]initWithRootViewController:[[ViewController alloc]init]];
self.window.rootViewController = nav;
return YES;
}
#import "ViewController.h"
#import "LGG_ViewController.h"
#import "AppDelegate.h"
@interface ViewController ()
@property (retain) UIButton* btn;
@property (retain) UILabel* Txt;
@property (retain)LGG_ViewController* lggVC;
@end
@implementation ViewController
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
UIApplication* app = [UIApplication sharedApplication];
AppDelegate* delegate = app.delegate;
if (delegate.label.length > 0) {
UILabel* txt = [self.view viewWithTag:delegate.num+19];
txt.text = delegate.label;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.title = @"画册";
_lggVC = [[LGG_ViewController alloc]init];
CGFloat Width = [UIScreen mainScreen].bounds.size.width;
CGFloat Height = [UIScreen mainScreen].bounds.size.height;
UIScrollView* sctollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, Width, Height-120)];
[self.view addSubview:sctollView];
CGFloat imageViewWidth = Width/4;
CGFloat imageViewHeight = imageViewWidth/2*3;
NSArray* Arr = @[@"32_1.jpg",@"32_2.jpg",@"32_3.jpg",@"32_4.jpg",@"32_5.jpg",@"32_6.jpg",@"32_7.jpg",@"32_8.jpg",@"32_9.jpg",@"32_10.jpg",@"32_11.jpg",@"32_12.jpg",@"32_13.jpg",@"32_14.jpg",@"32_15.jpg",@""];
NSInteger k = 0;
for (NSInteger i = 0; i < 4; i++) {
for (NSInteger j = 0; j < 4; j++) {
_btn = [UIButton buttonWithType:UIButtonTypeCustom];
_btn.frame = CGRectMake(imageViewWidth*j, imageViewHeight*i, imageViewWidth, imageViewHeight);
[_btn setImage:[UIImage imageNamed:Arr[k]] forState:UIControlStateNormal];
[_btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
_btn.tag = k+1;
[sctollView addSubview:_btn];
_Txt = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, _btn.frame.size.width, 30)];
_Txt.textColor = [UIColor greenColor];
NSUserDefaults* ud = [NSUserDefaults standardUserDefaults];
NSString* str = [ud objectForKey:[NSString stringWithFormat:@"%ld",_btn.tag]];
if (str.length > 0) {
_Txt.text = str;
}else{
_Txt.text = Arr[k];
}
_Txt.tag = k+20;
_Txt.textAlignment = NSTextAlignmentCenter;
[_btn addSubview:_Txt];
k++;
}
}
self.automaticallyAdjustsScrollViewInsets = NO;
sctollView.contentSize = CGSizeMake(0,imageViewHeight*4);
sctollView.bounces = NO;
}
-(void)btnAction:(UIButton*)sender
{
UIApplication* app = [UIApplication sharedApplication];
AppDelegate* delegate = app.delegate;
delegate.image = [UIImage imageNamed:[NSString stringWithFormat:@"32_%ld.jpg", (long)sender.tag]];
delegate.num = sender.tag;
[self.navigationController pushViewController:_lggVC animated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
#import "LGG_ViewController.h"
#import "AppDelegate.h"
@interface LGG_ViewController ()
@property (retain)UIImageView* imageView;
@property (retain)UITextField* txtField;
@end
@implementation LGG_ViewController
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
UIApplication* app = [UIApplication sharedApplication];
AppDelegate* delegate = app.delegate;
_imageView.image = delegate.image;
_txtField.text = @"";
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
CGFloat Width = [UIScreen mainScreen].bounds.size.width;
CGFloat Height = [UIScreen mainScreen].bounds.size.height;
_txtField = [[UITextField alloc]initWithFrame:CGRectMake(0, 64, Width, 50)];
_txtField.backgroundColor = [UIColor grayColor];
_txtField.placeholder=@"请输入照片名字";
_txtField.clearButtonMode=UITextFieldViewModeAlways;
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
[self.view addGestureRecognizer:tap];
[self.view addSubview:_txtField];
_imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 114, Width, Height-114)];
[self.view addSubview:_imageView];
UIButton* rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
rightBtn.frame = CGRectMake(0, 0, 50, 30);
[rightBtn setTitle:@"完成" forState:UIControlStateNormal];
[rightBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[rightBtn addTarget:self action:@selector(rightAction:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
}
-(void)rightAction:(UIBarButtonItem*)sender
{
UIApplication* app = [UIApplication sharedApplication];
AppDelegate* delegate = app.delegate;
delegate.label = _txtField.text;
NSUserDefaults* ud = [NSUserDefaults standardUserDefaults];
if (![_txtField.text isEqual:@""]) {
delegate.label = _txtField.text;
[ud setObject:delegate.label forKey:[NSString stringWithFormat:@"%ld",(long)delegate.num]];
}
[self.navigationController popViewControllerAnimated:YES];
}
-(void)tapAction:(UITapGestureRecognizer*)sender
{
[_txtField resignFirstResponder];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end