#在蓝懿学习iOS的日子#day15
1动态算高度:是为了修改行高的
UILabel *myLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
myLabel.backgroundColor = [UIColor yellowColor];
myLabel.numberOfLines = 0;
[self.view addSubview:myLabel];
myLabel.text = @"奥迪飞机";
//计算文本的高度
CGRect rect = [myLabel.text boundingRectWithSize:CGSizeMake(myLabel.bounds.size.width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:myLabel.font} context:nil];
NSLog(@"%f",rect.size.height);
// self.myLabel.frame = CGRectMake(self.myLabel.frame.origin.x, self.myLabel.frame.origin.y, self.myLabel.frame.size.width, rect.size.height);
//修改frame里面的某一个值 可以用下面的方式
CGRect frame = myLabel.frame;
frame.size.height = rect.size.height;
myLabel.frame = frame;
}
2tableHeaderView tableFooterView相当于微博里得上下边栏
- (void)viewDidLoad {
[super viewDidLoad];
self.myLabel.text = @"adsfasdf";
}
- (void)viewDidLoad {
[super viewDidLoad];
self.myLabel.text = @"adsfasdf";
}
3.文件管理器,:便于文件的管理
self.filePaths = [NSMutableArray array];
//如果是第一次 就显示固定路径下面的内容
if (!self.direcotryPath) {
self.direcotryPath = @"/Users/ivan";
}
self.title = [self.direcotryPath lastPathComponent];
NSString *path = self.direcotryPath;
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *fileNames = [fm contentsOfDirectoryAtPath:path error:nil];
for (NSString *fileName in fileNames) {
if (![fileName hasPrefix:@"."]) {
NSString *filePath = [path stringByAppendingPathComponent:fileName];
[self.filePaths addObject:filePath];
}
}
4.取地址 在文档里搜索文件
(1)// Person.h创建一个类生命两个属性
@property (nonatomic)int age;
@property (nonatomic)NSString *name;
(2)ViewController.m引用类
- (void)viewDidLoad {
[super viewDidLoad];
int x = 10;
[self changeX:&x];
NSLog(@"%d",x);
Person *p = [[Person alloc]init];
p.age = 18;
[self changeAge:&p];
NSLog(@"%d",p.age);
}
-(void)changeX:(int *)y{
*y = 5;
}
-(void)changeAge:(Person **)p1{
*p1 = [[Person alloc]init];
(*p1).age = 28;
}
5.递归
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *myTF;
@property (weak, nonatomic) IBOutlet UISwitch *mySwitch;
@property (weak, nonatomic) IBOutlet UITextView *historyTV;
@property (nonatomic)int count;
@end
@implementation ViewController
- (IBAction)clicked:(id)sender {
self.historyTV.text = @"";
[self findFileInDirecotry:@"/Users/ivan/Desktop"];
self.myTF.text = @"";
//收软键盘
[self.myTF resignFirstResponder];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)findFileInDirecotry:(NSString *)path{
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *fileNames = [fm contentsOfDirectoryAtPath:path error:nil];
for (NSString *fileName in fileNames) {
NSString *filePath = [path stringByAppendingPathComponent:fileName];
if (self.mySwitch.isOn) {//精确查找
if ([fileName isEqualToString:self.myTF.text]) {
NSLog(@"%@--%d",filePath,self.count++);
self.historyTV.text = [self.historyTV.text stringByAppendingFormat:@"\n%@",filePath];
}
}else{//模糊
if ([fileName rangeOfString:self.myTF.text].length>0) {
NSLog(@"%@--%d",filePath,self.count++);
self.historyTV.text = [self.historyTV.text stringByAppendingFormat:@"\n%@",filePath];
}
}
//如果是文件夹的话
BOOL isDir = NO;
if ([fm fileExistsAtPath:filePath isDirectory:&isDir]&&isDir) {
[self findFileInDirecotry:filePath];
}
}
}
6.查找工具
7.文件管理器