day6

## 计算某个文件\文件夹的大小

```objc

@implementation NSString (XMGExtension)

//- (unsigned long long)fileSize

//{

//    // 总大小

//    unsigned long long size = 0;

//

//    // 文件管理者

//    NSFileManager *mgr = [NSFileManager defaultManager];

//

//    // 文件属性

//    NSDictionary *attrs = [mgr attributesOfItemAtPath:self error:nil];

//

//    if ([attrs.fileType isEqualToString:NSFileTypeDirectory]) { // 文件夹

//        // 获得文件夹的大小  == 获得文件夹中所有文件的总大小

//        NSDirectoryEnumerator *enumerator = [mgr enumeratorAtPath:self];

//        for (NSString *subpath in enumerator) {

//            // 全路径

//            NSString *fullSubpath = [self stringByAppendingPathComponent:subpath];

//            // 累加文件大小

//            size += [mgr attributesOfItemAtPath:fullSubpath error:nil].fileSize;

//        }

//    } else { // 文件

//        size = attrs.fileSize;

//    }

//

//    return size;

//}

 

- (unsigned long long)fileSize

{

    // 总大小

    unsigned long long size = 0;

 

    // 文件管理者

    NSFileManager *mgr = [NSFileManager defaultManager];

 

    // 是否为文件夹

    BOOL isDirectory = NO;

 

    // 路径是否存在

    BOOL exists = [mgr fileExistsAtPath:self isDirectory:&isDirectory];

    if (!exists) return size;

 

    if (isDirectory) { // 文件夹

        // 获得文件夹的大小  == 获得文件夹中所有文件的总大小

        NSDirectoryEnumerator *enumerator = [mgr enumeratorAtPath:self];

        for (NSString *subpath in enumerator) {

            // 全路径

            NSString *fullSubpath = [self stringByAppendingPathComponent:subpath];

            // 累加文件大小

            size += [mgr attributesOfItemAtPath:fullSubpath error:nil].fileSize;

        }

    } else { // 文件

        size = [mgr attributesOfItemAtPath:self error:nil].fileSize;

    }

 

    return size;

}

@end

 

XMGLog(@"%zd", @"/Users/xiaomage/Desktop".fileSize);

```

 

## 计算文字的宽度

```objc

CGFloat titleW = [字符串 sizeWithFont:字体大小].width;

CGFloat titleW = [字符串 sizeWithAttributes:@{NSFontAttributeName : 字体大小}].width;

```

 

## 有透明度的颜色

```objc

[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.2];

[UIColor colorWithWhite:1.0 alpha:0.2];

[[UIColor whiteColor] colorWithAlphaComponent:0.2];

```

 

## viewWithTag:内部的大致实现思路

```objc

@implementation UIView

- (UIView *)viewWithTag:(NSInteger)tag

{

    if (self.tag == tag) return self;

 

    for (UIView *subview in self.subviews) {

        return [subview viewWithTag:tag];

    }

}

@end

```

 

转载于:https://www.cnblogs.com/finker/p/6535844.html

C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\Parser.js:437 throw err; // Rethrow non-MySQL errors ^ Error: secretOrPrivateKey must have a value at module.exports [as sign] (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\jsonwebtoken\sign.js:107:20) at Query.<anonymous> (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\router_handler\2user.js:49:26) at Query.<anonymous> (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\Connection.js:526:10) at Query._callback (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\Connection.js:488:16) at Sequence.end (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\sequences\Sequence.js:83:24) at Query._handleFinalResultPacket (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\sequences\Query.js:149:8) at Query.EofPacket (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\sequences\Query.js:133:8) at Protocol._parsePacket (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\Protocol.js:291:23) at Parser._parsePacket (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\Parser.js:433:10) at Parser.write (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\Parser.js:43:10) Node.js v18.12.1
06-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值