-
Notifications
You must be signed in to change notification settings - Fork 0
/
IOS.TXT.bak
354 lines (287 loc) · 11 KB
/
IOS.TXT.bak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
--==T:\ASNPGJK\Sources\IOS\IOS6~1\CH01_C~1\HELLOW~1\HELLOW~1\
HWViewController.h
@property (weak, nonatomic) IBOutlet UILabel *lblHelloWorld;
- (IBAction)doBtnHide:(id)sender;
HWViewController.m
- (IBAction)doBtnHide:(id)sender {
[lblHelloWorld setHidden:![lblHelloWorld isHidden]];
[sender setTitle:[lblHelloWorld isHidden] ? @"Show" : @"Hide" forState:UIControlStateNormal];
}
//
// HelloWorldViewController.h
// D01_HelloWorld
//
// Created by linlw on 13-5-29.
// Copyright (c) 2013年 linlw. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface HelloWorldViewController : UIViewController
-(IBAction)showMessage;
@end
//
// HelloWorldViewController.m
// D01_HelloWorld
//
// Created by linlw on 13-5-29.
// Copyright (c) 2013年 linlw. All rights reserved.
//
#import "HelloWorldViewController.h"
@interfaceHelloWorldViewController ()
@end
@implementation HelloWorldViewController
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)showMessage{
UIAlertView *helloWorldAlter = [[UIAlertViewalloc] initWithTitle:@"My First App"message:@"Hello World!"delegate:nilcancelButtonTitle:@"OK"otherButtonTitles:nil];
[helloWorldAlter show];
}
@end
SimpleTableViewController.h
#import <UIKit/UIKit.h>
@interface SimpleTableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@end
SimpleTableViewController.m
@implementation SimpleTableViewController {
NSArray *tableData;
}
- (void)viewDidLoad{
[super viewDidLoad];
// Initialize table data
tableData = [NSArray arrayWithObjects:@"Egg Benedict",
@"Mushroom Risotto", @"Full Breakfast", @"Hamburger", @"Ham and Egg Sandwich", @"Creme Brelee", @"White Chocolate Donut", @"Starbucks Coffee", @"Vegetable Curry", @"Instant Noodle with Egg", @"Noodle with BBQ Pork", @"Japanese Noodle with Pork", @"GreenTea", @"Thai Shrimp Cake", @"Angry Birds Cake", @"Ham and Cheese Panini", nil];
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return [tableData count]; }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:@"creme_brelee.jpg"];
return cell;
}
T:\ASNPGJK\Sources\IOS\IOS6~1\CH03_C~1\PicDecor\Classes\
MovableImageView.m
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
float deltaX = [[touches anyObject] locationInView:self].x - [[touches anyObject] previousLocationInView:self].x;
float deltaY = [[touches anyObject] locationInView:self].y - [[touches anyObject] previousLocationInView:self].y;
self.transform = CGAffineTransformTranslate(self.transform, deltaX, deltaY);
}
VCImageEditing.m
-(IBAction)doDecorateBtn:(id)sender;
{
selectingImage = YES;
[self presentModalViewController:vcDecorations animated:YES];
}
+ (UIImage*)imageWithImage:(UIImage*)image
scaledToSize:(CGSize)newSize;
{
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
-(UIImage *)saveImage:(UIView *)view {
CGRect mainRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(mainRect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(context, mainRect);
[view.layer renderInContext:context];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
-(IBAction)doEmailBtn:(id)sender;
{
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
// hide the toolbar
for (UIView *v in [self.view subviews])
if ([v isKindOfClass:[UIToolbar class]])
[v setHidden:YES];
UIImage *i = [self saveImage:self.view];
// show the toolbar
for (UIView *v in [self.view subviews])
if ([v isKindOfClass:[UIToolbar class]])
[v setHidden:NO];
NSData *imageAsData = UIImagePNGRepresentation(i);
[mailController addAttachmentData:imageAsData mimeType:@"image/png" fileName:@"PicDecor.png"];
[mailController setSubject:@"My PicDecor Image"];
[self presentModalViewController:mailController animated:YES];
[mailController release];
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(@"image: %@", editImage);
if (editImage != nil)
{
[ivEditingImage setImage:editImage];
[self.view sendSubviewToBack:ivEditingImage];
}
if (selectingImage)
{
MovableImageView *iv =
[[[MovableImageView alloc]
initWithImage:[vcDecorations selectedImage]] autorelease];
[iv setUserInteractionEnabled:YES];
[self.view addSubview:iv];
}
selectingImage = NO;
}
VCDecorations.m
-(IBAction)doImageBtn:(id)sender;
{
[selectedImage release];
selectedImage = [[sender backgroundImageForState:UIControlStateNormal] retain];
[self dismissModalViewControllerAnimated:YES];
}
-(IBAction)doCancelBtn:(id)sender;
{
[self dismissModalViewControllerAnimated:YES];
}
PicDecorViewController.m
- (UIImage*)imageWithImage:(UIImage*)image
scaledToSize:(CGSize)newSize;
{
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *i = [info objectForKey:UIImagePickerControllerOriginalImage];
NSLog(@"%f %f", [i size].width, [i size].height);
if (i.size.width > 320 || i.size.height > 480)
i = [self imageWithImage:i scaledToSize:CGSizeMake(320, 480)];
[self dismissModalViewControllerAnimated:NO];
[vcImageEditing setEditImage:i];
[self presentModalViewController:vcImageEditing animated:YES];
}
-(IBAction)doCameraBtn:(id)sender;
{
UIImagePickerController *ipController = [[[UIImagePickerController alloc] init] autorelease];
if ([[[UIDevice currentDevice] model]
rangeOfString:@"Sim"].location == NSNotFound)
[ipController setSourceType:UIImagePickerControllerSourceTypeCamera];
[ipController setDelegate:self];
[self presentModalViewController:ipController animated:YES];
}
-(IBAction)doPhotoAlbumBtn:(id)sender;
{
UIImagePickerController *ipController = [[[UIImagePickerController alloc] init] autorelease];
[ipController setDelegate:self];
[self presentModalViewController:ipController animated:YES];
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if (!startedUp)
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
[self doPhotoAlbumBtn:nil];
startedUp = YES;
}
IOS开发从入门到精通 P176
#if 0
//创建UILable对象
UILabel* label = [[UILabel alloc] initWithFrame:self.view.bounds];
label.text = @"This is a UILabel Demo,";
label.font = [UIFont fontWithName:@"Arial" size:35];
label.textColor = [[UIColor yellowColor];
label.textAligment = UITextAligmentCenter;
label.backgroundColor = [UIColor blueColor];
label.bcakBreakMode = UILineBreakModeWordWrap;
label.numberOfLines = 0;
CGSize size = [label.text sizeWithFont:label.fontconstrainedToSize:self.view.bounds.size lineBreakMode:label.lineBreakMode];
CGRect rect = label.frame;
rect.size.height = size.height;
label.frame = rect;
#endif
#if 1
//自定义控件UILableEx需重写父类,具体实现 UILableEx.h/UILabelEx.m, 见IOS开发从入门到精通 P177
UILabelEx* label = [[UILabelEx alloc] initWithFrame:self.view.bounds];
label.text = @"This is a UILabel Demo,";
label.font = [UIFont fontWithName:@"Arial" size:35];
label.textColor = [[UIColor yellowColor];
label.textAligment = UITextAligmentCenter;
label.backgroundColor = [UIColor blueColor];
label.bcakBreakMode = UILineBreakModeWordWrap;
label.numberOfLines = 0;
label.verticalAligment = VerticalAlignmentTop;
#endif
[self.view addSubView:label];
[label release];
IOS开发从入门到精通 P191
//自定义按键图片
UIImage *normalImage = [[UIImage imageNamed:@"WhiteButton.png"] stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0];
UIImage *pressedImage = [[UIImage imageNamed:@"blueButton.png"] stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0];
[self.theButton setBackgroundImage:normalImage forState:UIControlStateNormal];
[self.theButton setBackgroundImage:pressedImage forState:UIControlStateHighlighted];
[super viedDidLoad];
IOS开发从入门到精通 P195
//用占位符替换生成文本
- (IBAction)createStory:(id)sender {
self.theStory.text = [self.theTemplate.text stringByReplacingOccurrencesOfString:@"<place" withString:self.thePlace.text];
}
IOS开发从入门到精通 P194
//隐藏键盘代码
- (IBAction)hideKeyboard:(id)sender {
[self.thePlace resignFirstResponder];
[self.theNumber resignFirstResponder];
}
IOS开发从入门到精通 P155
//实现MSGBOX
-(IBAction)buttonPressed1{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示"
message:@"内容"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
-(IBAction)buttonPressed1234{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示"
message:@"请选择一个按钮:"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"按钮一",@"按钮二",@"按钮三",nil];
[alert show];
[alert release];
}
//在clickedButtonAtIndex中检测buttonIndex,以判断第几个按钮,0=取消,1=按钮一,2=按钮二,3=按钮三
-(void)alterView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger) ButtonIndex{
NSString* msg = [[NSString alloc]initWithFormat:@"你按下的第%d个按钮!",buttonIndex];
UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"提示"
message:msg
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
[alert release];
[msg release];
}