project-Normal
该项目收集了一些常用的快捷方法。
更新日志
2018-6-15
- 1. 通过
redrawImageWithColor:
添加使用颜色重新绘制图像。
2018-5-31
- 1. 移除了常规组件。
- 2. 添加文本字段占位文本颜色。
- 3. 添加法律检查。
NSDataGeneral
/// The NSData object is transformed into a string.
@property (copy, nonatomic, readonly) NSString *string;
/// If the object satisfies the json requirement, the NSData object is transformed directly into an NSDictionary object.
@property (copy, nonatomic, readonly) NSDictionary *map;
NSDateGeneral
/**
Convert the timestamp directly into a string in the specified format.
@param interval The time stamp.
@param format String format.
@return The time string.
*/
extern NSString *Interval2Str(NSTimeInterval interval, NSDateFormatType format);
/**
Use the dateFormat to format the NSDate object.
@param dateFormat The format of date.
@return The formatted string.
*/
- (NSString *)dateStringWithFormat:(NSDateFormatType)dateFormat;
- (NSString *)stringFormDateWithFormat:(NSString *)format;
/**
Converts a dateFormat string into an NSDate object.
@param dateString The date string.
@param dateFormat The date string format.
@return NSDate object.
*/
+ (NSDate *)dateFromDateString:(NSString *)dateString withFormat:(NSDateFormatType)dateFormat;
+ (NSDate *)dateFromDateString:(NSString *)dateString byUsingFromat:(NSString *)format;
#pragma mark - Compare
/**
Compare two NSDate objects to get the time interval.
@return The comparison results are represented by strings, such as: 10 minutes ago, a week ago, etc.
*/
- (NSString *)distanceToCurrent;
NSStringGeneral
#pragma mark - Encrypt by using MD5
/// Encrypt the string by using md5.
@property (copy, nonatomic, readonly) NSString *MD5;
#pragma mark - Encrypt by using AES128
/**
Encrypt the string using AES128.
@param key Encrypt the key used.
@param iv The amount of offsets used for encryption.
@return The encrypted string.
*/
- (NSString *)encryptedWithAES128UsingKey:(NSString*)key andIV:(NSString *)iv;
/**
The encrypted AES128 string is decrypted.
@param key Dencrypt the key used.
@param iv The amount of offsets used for dencryption.
@return Decrypted string.
*/
- (NSString *)decryptedWithAES128UsingKey:(NSString*)key andIV:(NSString *)iv;
#pragma mark - String size
/**
The size of a string is dynamically calculated by the font size. If the calculated size exceeds the constraint size, use the constraint size directly.
@param font The font of string.
@param size Constraint size. If it is zero, it means that a row has no length.
@return The size of the text in the UIKit coordinate system.
*/
- (CGSize)boundingSizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size;
#pragma mark - Pinyin Refer from: https://github.com/croath/NSString-Pinyin
- (NSString *)pinyinWithPhoneticSymbol;
- (NSString *)pinyin;
- (NSArray *)pinyinArray;
- (NSString *)pinyinWithoutBlank;
- (NSArray *)pinyinInitialsArray;
- (NSString *)pinyinInitialsString;
UIColorGeneral
/**
Get the UIColor object through the sixteen binary value and transparency of the color.
@param hex Sixteen decimal values through the color.
@param alpha Sixteen decimal values through the color.
@return The UIColor object.
*/
+ (UIColor *)colorWithHex:(int)hex alpha:(CGFloat)alpha;
/**
Get the UIColor object through the sixteen binary value and transparency of the color.
@param hex Sixteen decimal values through the color.
@return The UIColor object which alpha=1.0.
*/
+ (UIColor *)colorWithHex:(int)hex;
/**
Change color to a size image.
@param size The size of the image to be generated.
@return Generated image object.
*/
- (UIImage *)imageFromUIColorWithSize:(CGSize)size;
UIImageGeneral
/**
High performance to add rounded corners to images.
@param radius Corner radius.
@return A cropped image.
*/
- (UIImage *)imageWithCornerRadius:(CGFloat)radius;
UIScreenGeneral
/// Classification of devices based on screen features.
typedef NS_ENUM(NSInteger, UIScreenType) {
/// Width = 375
iPhone6,
/// Width = 414
iPhone6Plus,
/// Width = 320
iPhone5,
/// Height = 812
iPhoneX
};
/// The ratio of the current screen width to the width of the iPhone6.
#define UIScreenRatioByWidthFromIPhone6 ([UIScreen mainScreen].width/375)
#define UIStatusBarHeight ([UIApplication sharedApplication].statusBarFrame.size.height)
#define UIBottomSafeAreaHeight ([UIScreen mainScreen].height == 812 ? 34.0 : 0.0)
/// Gets the current hardware device model by using screen type.
#define UICurrentDevice (\
[UIScreen mainScreen].height == 812 ? iPhoneX : \
([UIScreen mainScreen].width == 375 ? iPhone6 : \
([UIScreen mainScreen].width == 414 ? iPhone6Plus : iPhone5) \
) \
)
UIKIT_EXTERN CGFloat UINavigationBarHeight;
@interface UIScreen (General)
/// Rename 'mainScreen' method.
+ (instancetype)main;
/// Shortcut to get the screen width.
@property (assign, nonatomic, readonly) CGFloat width;
/// Shortcut to get the screen height.
@property (assign, nonatomic, readonly) CGFloat height;
/// Minimum value in the border length.
@property (assign, nonatomic, readonly) CGFloat minimumBorder;
@end
UIViewGeneral
#pragma mark - Nib
/**
Load the class view object in Xib. The name of xib must be the same as the class name, and the view in xib needs to use that class.
@return The view which named by self.
*/
+ (instancetype)fromNib;
/**
Load the xib file using the view class name.
@return The UINib object.
*/
+ (UINib *)nib;
#pragma mark - Frame
@property (assign, nonatomic) CGFloat x;
@property (assign, nonatomic) CGFloat y;
@property (assign, nonatomic) CGFloat w;
@property (assign, nonatomic) CGFloat h;
@property (assign, nonatomic) CGSize size;
@property (assign, nonatomic) CGPoint origin;
UITextFieldGeneral
/**
Sets the placeholder color for the text input box.
@param placeholderColor The placeholder color.
*/
- (void)setPlaceholderColor:(nonnull UIColor *)placeholderColor;