iphone 开发 杂记

//时间比较
NSDate * temp = [[NSDate alloc]init];
NSDate * last = [[NSDate alloc]init];
NSComparisonResult a = [ temp compare:last  ];
if (NSOrderedAscending == a) {//如果temp比last早
    NSLog(@"zao");
} else {
    NSLog(@"b zao");
}


//input常用的连个属性
[input setBorderStyle:UITextBorderStyleRoundedRect];
[input setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];


//弹出浏览器
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com/"]];

//复制到粘贴板
 UIPasteboard *pasteboard=[UIPasteboard generalPasteboard];
pasteboard.string =@"sssss"; 


//定时任务:
[self performSelector:@selector(performDismiss) withObject:nil afterDelay:3.0f];


//设置uibutton事件,通过tag传递参数
[cell.deleteView setTag:row]; //设置tag位行号,以达到传递参数的目的
[cell.deleteView addTarget:self action:@selector(onDelete:) forControlEvents:UIControlEventTouchUpInside];
//使用
-(void)onDelete:(id)sender{
    UIButton * button = (UIButton*)sender;
    int row = button.tag;
...
}


//设置导航条右上角按钮
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]...

//设置界面事件方法:
-(IBAction)buttonClick:(id)sender;


//时间计算
 NSDate * bDate = [[NSDate alloc]init];//开始时间,现在
 NSTimeInterval minute30 = 30*60; //结束时间 设置在开始时间30分钟后
 NSDate * edate = [order.receiveTime dateByAddingTimeInterval:minute30];


//cell最常用3个方法
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];//右边的箭头
cell.textLabel.text = [self str:@"decode"];//文本
cell.imageView.image = [UIImage imageNamed:@"icon_decode.png"];//左边的图标

//状态栏中加载中的图标
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO; //关闭状态栏,加载中的提示图标



//使每次点击UITabBarController的tab时返回到第一页
self.tabBarController.delegate = self;
//使每次点击tab都回到跟目录
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
	if ([viewController isKindOfClass:[UINavigationController class]]) {
		[(UINavigationController *)viewController popToRootViewControllerAnimated:YES];
	}
}


//设置图片按比例缩放
[imageView setContentMode:UIViewContentModeScaleAspectFit];


//设置UIImageView边框   需要在.pch文件中添加#import <QuartzCore/CALayer.h>
 CALayer * layer = [imageView layer];
[layer setMasksToBounds:YES]; //是否设置边框以及是否可见       
[layer setCornerRadius:10.0]; //设置边框圆角的弧度        
[layer setBorderWidth:1];//设置边框线的宽       
[layer setBorderColor:[[UIColor blackColor] CGColor]]; //设置边框线的颜色


//日期时间格式化
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];  
[dateFormatter setDateFormat:@"yyyy-MM-dd"];  
lblBirth.text = [dateFormatter stringFromDate:student.birth]; 

猜你喜欢

转载自zheyiw.iteye.com/blog/1673024