说明 | 时间 |
---|---|
首次发布 | 2017年05月21日 |
最近更新 | 2020年05月04日 |
1、获取设备信息
//MZDeviceInfo.h
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface MZDeviceInfo : NSObject
///获取设备型号
+ (NSString *)deviceModel;
///获取设备版本号
+ (NSString *)systemVersion;
@end
NS_ASSUME_NONNULL_END
//.m
#import "MZDeviceInfo.h"
#import <UIKit/UIDevice.h>
#import <sys/utsname.h>
@implementation MZDeviceInfo
+ (NSString *)systemVersion {
return [[UIDevice currentDevice] systemVersion];
}
+ (NSString *)deviceModel {
NSString *deviceModel = [[self class] currentModel];
if (deviceModel.length == 0) {
deviceModel = @"unknown device";
}
return deviceModel;
}
+ (NSString *)currentModel {
struct utsname systemInfo;
uname(&systemInfo);
NSString *platformName = [NSString stringWithCString: systemInfo.machine encoding:NSASCIIStringEncoding];
return [[self machineModels] objectForKey:platformName];
}
+ (NSDictionary *)machineModels {
static NSDictionary *_machineModels = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_machineModels = @{@"iPhone1,1": @"iPhone 2G",
@"iPhone1,2": @"iPhone 3G",
@"iPhone2,1": @"iPhone 3GS",
@"iPhone3,1": @"iPhone 4",
@"iPhone3,2": @"iPhone 4",
@"iPhone3,3": @"iPhone 4",
@"iPhone4,1": @"iPhone 4s",
@"iPhone5,1": @"iPhone 5",
@"iPhone5,2": @"iPhone 5",
@"iPhone5,3": @"iPhone 5c",
@"iPhone5,4": @"iPhone 5c",
@"iPhone6,1": @"iPhone 5s",
@"iPhone6,2": @"iPhone 5s",
@"iPhone7,1": @"iPhone 6 Plus",
@"iPhone7,2": @"iPhone 6",
@"iPhone8,1": @"iPhone 6s",
@"iPhone8,2": @"iPhone 6s Plus",
@"iPhone8,4": @"iPhone SE",
@"iPhone9,1": @"iPhone 7",
@"iPhone9,2": @"iPhone 7 Plus",
@"iPhone10,1": @"iPhone 8",
@"iPhone10,2": @"iPhone 8 Plus",
@"iPhone10,3": @"iPhone X",
@"iPhone10,4": @"iPhone 8",
@"iPhone10,5": @"iPhone 8 Plus",
@"iPhone10,6": @"iPhone X",
@"iPhone11,2": @"iPhone XS",
@"iPhone11,4": @"iPhone XS Max",
@"iPhone11,6": @"iPhone XS Max",
@"iPhone11,8": @"iPhone XR",
@"iPad1,1": @"iPad 1G",
@"iPad2,1": @"iPad 2",
@"iPad2,2": @"iPad 2",
@"iPad2,3": @"iPad 2",
@"iPad2,4": @"iPad 2",
@"iPad2,5": @"iPad Mini 1G",
@"iPad2,6": @"iPad Mini 1G",
@"iPad2,7": @"iPad Mini 1G",
@"iPad3,1": @"iPad 3",
@"iPad3,2": @"iPad 3",
@"iPad3,3": @"iPad 3",
@"iPad3,4": @"iPad 4",
@"iPad3,5": @"iPad 4",
@"iPad3,6": @"iPad 4",
@"iPad4,1": @"iPad Air",
@"iPad4,2": @"iPad Air",
@"iPad4,3": @"iPad Air",
@"iPad4,4": @"iPad Mini 2G",
@"iPad4,5": @"iPad Mini 2G",
@"iPad4,6": @"iPad Mini 2G",
@"iPad4,7": @"iPad Mini 3",
@"iPad4,8": @"iPad Mini 3",
@"iPad4,9": @"iPad Mini 3",
@"iPad5,1": @"iPad Mini 4",
@"iPad5,2": @"iPad Mini 4",
@"iPad5,3": @"iPad Air 2",
@"iPad5,4": @"iPad Air 2",
@"iPad6,3": @"iPad Pro 9.7",
@"iPad6,4": @"iPad Pro 9.7",
@"iPad6,7": @"iPad Pro 12.9",
@"iPad6,8": @"iPad Pro 12.9",
@"iPod1,1": @"iPod Touch 1G",
@"iPod2,1": @"iPod Touch 2G",
@"iPod3,1": @"iPod Touch 3G",
@"iPod4,1": @"iPod Touch 4G",
@"iPod5,1": @"iPod Touch 5G",
@"i386": @"iPhone Simulator 32bit",
@"x86_64": @"iPhone Simulator 64bit",
};
});
return _machineModels;
}
@end
给文字添加删除线
在原有的属性字典里添加 NSBaselineOffsetAttributeName
(基线偏移值:取值为NSNumber (float),正值上偏,负值下偏)就可以了 。
iOS10.3之前的写法是:
NSAttributedString *attributedString = [[NSAttributedString alloc]
initWithString:goodsprice attributes:@{
NSStrikethroughStyleAttributeName :@(NSUnderlineStyleSingle),
NSStrikethroughColorAttributeName : UIColorFromHexValue(0xBBBBBB)
}];
seckillLabel.attributedText = attributedString;
iOS10.3之后的写法是:
NSAttributedString *attributedString = [[NSAttributedString alloc]
initWithString:goodsprice attributes:@{
NSStrikethroughStyleAttributeName : @(NSUnderlineStyleSingle),
NSStrikethroughColorAttributeName : UIColorFromHexValue(0xBBBBBB),
NSBaselineOffsetAttributeName:@(0)}];//NSBaselineOffsetAttributeName 设置基线偏移值。取值为NSNumber (float),正值上偏,负值下偏
cell.seckillLabel.attributedText = attributedString;