您的位置:首页 > 移动开发 > IOS开发

IOS 小知识总结

2013-11-21 10:40 309 查看
为UIImageView添加单击事件:

-------初始化一个Image-------

imageView.userInteractionEnabled = YES;

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(yourHandlingCode:)];

[imageView addGestureRecognizer:singleTap];

,UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>{

-------属于某一个类--------

 if([view isKindOfClass:[UITabBar class]]) 

-------初始化BUtton--------

loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
[loginButton setFrame:CGRectMake(470, 485, 119, 59)];
[loginButton setBackgroundImage:[UIImage imageNamed:@"login_button.png"] forState:UIControlStateNormal];
[loginButton addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];

-------初始化一个Image-------

passwordLabel = [[UIImageView alloc] initWithFrame:CGRectMake( 332, 420, 60, 60)];
passwordLabel.image = [UIImage imageNamed:@"Key.png"];
[self.view addSubview:passwordLabel];

passwordField = [[UITextField alloc] initWithFrame:CGRectMake( 415, 440, 220, 21)];
passwordField.autocorrectionType = UITextAutocorrectionTypeNo;
passwordField.clearButtonMode = UITextFieldViewModeWhileEditing;
passwordField.clearsOnBeginEditing = NO;

passwordField.font = [UIFont systemFontOfSize:20];
passwordField.secureTextEntry = YES;
passwordField.placeholder = @"Password";
passwordField.delegate = self;
[self.view addSubview:passwordField];

------------------UIImageView--------------------

imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(398, 350, 275, 58)];
imageView1.image = [UIImage imageNamed:@"login_cell.png"];

------------------UIAlertView---------------------

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"是否确定切换用户?" 
message:@"切换用户会清空当前登录用户的任务观察记录"
  delegate:self 
 cancelButtonTitle:@"取消" otherButtonTitles:@"切换",nil];

 *alert = [[UIAlertView alloc] initWithTitle:@"是否确定切换用户?" 
message:@"切换用户会清空当前登录用户的任务观察记录"
  delegate:self 
 cancelButtonTitle:@"取消" otherButtonTitles:@"切换",nil];

----------------------thread------------------------
NSThread *thread=[[NSThread alloc]initWithTarget:self selector:@selector(run) object:nil];

[thread setName:@"GO"];
[thread start];

[self performSelectorOnMainThread:@selector(finished) withObject:nil waitUntilDone:YES];

----------------------main------------------------

MainViewController *mainView = [[MainViewController alloc] init];
[[(TaskObserveAppDelegate *)[[UIApplication sharedApplication] delegate] window] addSubview:mainView.view];
[self.view removeFromSuperview];
self.view = nil;

----------------------button------------------------

UIButton *taskButton = [UIButton buttonWithType:UIButtonTypeCustom];
[taskButton setFrame:CGRectMake(340, 650, 90, 90)];
[taskButton setBackgroundImage:[UIImage imageNamed:@"task_bg_.png"] forState:UIControlStateNormal];
[taskButton addTarget:self action:@selector(taskButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

---------------UITableView------------

UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 748)];
UIImageView *taskimage = [[UIImageView alloc] initWithFrame:CGRectMake(0, -30, 1024, 748)];
taskimage.image = [UIImage imageNamed:@"task_table_image.png"];
[view1 addSubview:taskimage];

listView = [[UITableView alloc] initWithFrame:CGRectMake(59, 105, 900, 426) style:UITableViewStylePlain];
listView.delegate = self;
listView.dataSource = self;
listView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[listView setBackgroundColor:[UIColor clearColor]];

[self getlistArray];
[view1 addSubview:listView];
[scrollView addSubview:view1];

----------- cell------------------------

WorkListCell *cell = (WorkListCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"WorkListCell" owner:self options:nil] lastObject];
cell.idLabel.text = [[listArray objectAtIndex:indexPath.row] observe_number];
[cell.idLabel setTextColor:WORD_COLOR];

-----------转圈---------------------
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];

----------------requst--------------------------

if (stdDown && stdDown.downUrl) {
ASIHTTPRequest *request2 = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:stdDown.downUrl]];
[request2 setTimeOutSeconds:600];
[request2 setDelegate:self];
NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *dbPath = [documentPath stringByAppendingPathComponent:@"TASKVIEWSTD.DB"];
[request2 setDownloadDestinationPath:dbPath];
[request2 startAsynchronous];

--------------requestFailed-------------------

- (void)requestFailed:(ASIHTTPRequest *)request{
NSError *error = [request error];
[alert dismissWithClickedButtonIndex:0 animated:YES];
if ([error localizedDescription]) {
alert = [[UIAlertView alloc] initWithTitle:@"下载标准库错误:" 
  message:[error localizedDescription]
 
 delegate:self 
cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alert show];
}

}

-------------------color-------------------

[cell.timeLabel setTextColor:WORD_COLOR];

#define WORD_COLOR UIColorFromRGB(0x50729f)

#define ROATE NO

-----------转换----------------------

[ActionViewController setObserveInfo:(ObserveInfo *)[listArray objectAtIndex:indexPath.row]];

12、页面切换效果设置:

controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

[self presentModalViewController:controller animated:YES];

可供使用的效果:

UIModalTransitionStyleCoverVertical

UIModalTransitionStyleFlipHorizontal

UIModalTransitionStyleCrossDissolve

UIModalTransitionStylePartialCurl

恢复之前的页面:

[self dismissModalViewControllerAnimated:YES];

4、设置和获取类中属性值:

[self setValue: 变量值 forKey: 变量名];

[self valueForKey: 变量名];

5、让某一方法在未来某段时间之后执行:

[self performSelector:@selector(方法名) withObject:nil afterDelay:延迟时间(s)]; 

6、获得设备版本号:

float version = [[[UIDevice currentDevice] systemVersion] floatValue];

7、捕捉程序关闭或者进入后台事件:

UIApplication *app = [UIApplication sharedApplication];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:app];

applicationWillResignActive:这个方法中添加想要的操作

小知识点:
http://www.cocoachina.com/newbie/tutorial/2012/1016/4928.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: