#在蓝懿学习iOS的日子#day15
2015-11-09 20:05
148 查看
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.文件管理器
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.文件管理器
相关文章推荐
- iOS类簇(Class Cluster)使用心得
- iOS第三方支付(支付宝)
- iOS学习XMPP框架之使用DDLog打印日志
- iOS 关于萌(蒙)层的添加,
- iOS 上传云端代码
- IOS8 指纹解锁 Touch ID
- 海康SDK修改分辨率
- [iOS基础]文件读取详解
- Xcode 工程设置及含义
- iOS中的ARC---ARC规则
- IOS 百叶窗动画
- iOS-获取当前时间的年、月、日、时、分、秒
- 在 ios 与 android 同时支持js功能,即web与app的交互功能的实现
- iOS 更改textField里placeholder的字体和颜色
- ios 下拉列表
- 利用Core Plot绘制折线图
- iOS 9以上系统调用不了支付宝客户端只能调用网页解决方法
- nagios_自定义宏变量隐藏发送邮件账号的敏感信息
- iOS 中捕获程序崩溃日志
- 关于iOS9中的App Transport Security相关说明及适配