├── OSLogger_1.7.deb ├── OSLogger.plist ├── layout └── Library │ └── Application Support │ └── OSLogger.bundle │ └── OSL.png ├── control ├── Makefile ├── README.md ├── CMManager.h ├── Tweak.xm └── CMManager.m /OSLogger_1.7.deb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazymind90/OSLogger/HEAD/OSLogger_1.7.deb -------------------------------------------------------------------------------- /OSLogger.plist: -------------------------------------------------------------------------------- 1 | { 2 | Filter = { 3 | Bundles = ( 4 | "com.apple.UIKit" 5 | ); 6 | }; 7 | } -------------------------------------------------------------------------------- /layout/Library/Application Support/OSLogger.bundle/OSL.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazymind90/OSLogger/HEAD/layout/Library/Application Support/OSLogger.bundle/OSL.png -------------------------------------------------------------------------------- /control: -------------------------------------------------------------------------------- 1 | Package: com.crazymind90.oslogger 2 | Name: OSLogger 3 | Depends: mobilesubstrate 4 | Version: 0.0.1 5 | Architecture: iphoneos-arm 6 | Description: An awesome MobileSubstrate tweak! 7 | Maintainer: @CrazyMind90 8 | Author: @CrazyMind90 9 | Section: Tweaks 10 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ARCHS = arm64e arm64 armv7 armv7s 2 | 3 | THEOS_DEVICE_IP = 192.168.1.40 4 | 5 | DEBUG = 0 6 | 7 | include $(THEOS)/makefiles/common.mk 8 | 9 | TWEAK_NAME = OSLogger 10 | 11 | OSLogger_FILES = Tweak.xm CMManager.m 12 | OSLogger_CFLAGS = -fobjc-arc 13 | 14 | include $(THEOS_MAKE_PATH)/tweak.mk 15 | 16 | 17 | install:: 18 | install.exec 19 | 20 | 21 | install3:: 22 | install3.exec 23 | 24 | 25 | install2:: 26 | install2.exec 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OSLogger 2 | 3 | Simple tweak to display all the app NSLogs 4 | 5 | # To show 6 | Long press with two fingers for 1 sec 7 | 8 | # To dismiss 9 | Long press on #OSLogger icon 10 | 11 | 12 | 13 | # Supports iOS 12,13 and 14+ 14 | 15 | ### ScreenShots 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /CMManager.h: -------------------------------------------------------------------------------- 1 | // By @CrazyMind90 2 | 3 | #pragma clang diagnostic ignored "-Warc-performSelector-leaks" 4 | #pragma clang diagnostic ignored "-Wnullability-completeness" 5 | #pragma GCC diagnostic ignored "-Wunused-variable" 6 | #pragma GCC diagnostic ignored "-Wprotocol" 7 | #pragma GCC diagnostic ignored "-Wmacro-redefined" 8 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 9 | #pragma GCC diagnostic ignored "-Wincomplete-implementation" 10 | #pragma GCC diagnostic ignored "-Wunguarded-availability-new" 11 | 12 | #import 13 | #include 14 | #include 15 | #import 16 | #import 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | // #import "NSStrings.h" 23 | 24 | 25 | #define rgbValue 26 | #define UIColorFromHEX(rgbValue) [UIColor \ 27 | colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \ 28 | green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \ 29 | blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] 30 | 31 | 32 | #define SCREEN_WIDTH UIScreen.mainScreen.bounds.size.width 33 | 34 | #define SCREEN_HEIGHT UIScreen.mainScreen.bounds.size.height 35 | 36 | 37 | 38 | 39 | 40 | @interface CMManager : UIViewController 41 | 42 | @property (nonatomic, strong) NSString *ImageFullPath; 43 | 44 | +(UIMenu *) InitMenuOnButton:(UIButton *)Button MenuTitles:(NSArray *)MenuTitles ActionsTitles:(NSArray *)ActionsTitles ImagesNames:(NSArray *)ImagesNames Target:(id)Target Action:(SEL)Action handler:(void(^_Nullable)(NSString *ButtonTitle))handler; 45 | 46 | +(NSString *) RunCMDWithLog:(NSString *)RunCMDWithLog; 47 | 48 | +(void) InitAlertWithTitle:(NSString *_Nullable)Title Message:(NSString *_Nullable)Message Buttons:(NSArray *_Nullable)Buttons CancelButtonTitle:(NSString *_Nullable)CancelButtonTitle AlertStyle:(UIAlertControllerStyle)AlertStyle handler:(void(^_Nullable)(NSString * _Nullable ButtonTitle, NSUInteger index))handler; 49 | 50 | +(NSArray *_Nullable) InitLabelImage:(UIImage *_Nullable)image InView:(UIView *_Nullable)View LabelName:(NSString *)Name; 51 | 52 | +(NSArray *) InitButtonLabelWithName:(NSString *)Name InView:(UIView *)View Target:(id)Target Action:(SEL)Action; 53 | 54 | +(NSArray *_Nullable) InitButtonImage:(UIImage *_Nullable)image InView:(UIView *_Nullable)View Target:(id)Target Action:(SEL)Action; 55 | 56 | +(UISegmentedControl *) InitSegamentWithSections:(NSArray *)Sections Target:(id)Target Action:(SEL)Action InView:(UIView *)View; 57 | 58 | +(void) AlertWithTitle:(NSString *)Title Message:(NSString *)Message ButtonTitle:(NSString *)ButtonTitle; 59 | 60 | +(void) ForLoop:(NSMutableArray *)Array Handler:(void (^_Nullable) (NSUInteger Counter) )handler; 61 | 62 | +(void) ActivateThisCodeForTimes:(NSUInteger)Times handler:(void (^_Nullable) (void) )handler; 63 | 64 | +(void) ActiveThisCodeOneTime:(void (^_Nullable) (void) ) handler; 65 | 66 | +(void) SendGETtoPHP:(NSString *_Nullable)SendGETtoPHP handler:(void(^_Nullable)(NSString *Res))handler; 67 | 68 | +(NSMutableAttributedString *) OriginalText:(NSString *)OriginalText ChangeColorOfText:(NSArray *)Text ToColor:(NSArray *)Color; 69 | 70 | +(id) GeneratorTwos:(NSUInteger)Num; 71 | 72 | +(void) RemoveALLItemsInDirectory:(NSString *)Dir; 73 | 74 | +(NSString *) RemoveAllNumbersFromString:(NSString *)String; 75 | 76 | +(NSString *) RemoveAllLettersFromString:(NSString *)String; 77 | 78 | +(NSDictionary *) GetJSONFromURL:(NSString *)URL; 79 | 80 | +(UIImage *_Nullable) GenerateThumbImageFromPath:(NSString *_Nullable)Path; 81 | 82 | +(UIView *) InitNewViewInView:(UIView *)InView Frame:(CGRect)Frame; 83 | 84 | +(NSString *) SelfBundle; 85 | 86 | +(AVPlayer *) PlayVideoWithoutCotrollersInView:(UIView *)InView Frame:(CGRect)Frame CornerRadius:(float)CornerRadius VideoPath:(NSString *)VideoPath addObserver:(UIViewController *)Observer Action:(SEL)Action handler:(void(^_Nullable)(id _Nullable PrintThisNote))handler; 87 | 88 | +(BOOL) DownloadLink:(NSString *_Nullable)DownloadLink ToPath:(NSString *_Nullable)ToPath; 89 | 90 | +(void) UploadFile:(NSString *_Nullable)UploadFile PHPLink:(NSString *_Nullable)PHPLink PHPNameValue:(NSString *_Nullable)PHPNameValue; 91 | 92 | +(BOOL) CreateFileAtPath:(NSString *_Nullable)CreateDirectoryAtPath; 93 | 94 | +(BOOL) CreateDirectoryAtPath:(NSString *_Nullable)CreateDirectoryAtPath; 95 | 96 | +(BOOL) MoveItemAtPath:(NSString *_Nullable)CopyItemAtPath ToPath:(NSString *_Nullable)ToPath; 97 | 98 | +(BOOL) CopyItemAtPath:(NSString *_Nullable)CopyItemAtPath ToPath:(NSString *_Nullable)ToPath; 99 | 100 | +(BOOL) RemoveItemAtPath:(NSString *_Nullable)RemoveItemAtPath; 101 | 102 | +(BOOL) FileExistsAtPath:(NSString *_Nullable)FileExistsAtPath; 103 | 104 | +(BOOL) CreatePlistAtPath:(NSString *_Nullable)CreatePlistAtPath NameWithoutExtension:(NSString *_Nullable)NameWithoutExtension; 105 | 106 | +(id _Nullable) Generator:(NSUInteger)Num; 107 | 108 | +(NSString *_Nullable) PlistPath:(NSString *_Nullable)PlistPath ObjectForKey:(NSString *_Nullable)ObjectForKey; 109 | 110 | +(BOOL) PlistPath:(NSString *_Nullable)PlistPath SetValue:(id _Nullable )SetValue ForKey:(id _Nullable)ForKey; 111 | 112 | +(void) SendGETtoPHP:(NSString *_Nullable)SendGETtoPHP; 113 | 114 | +(id _Nullable ) DataPathWithFileOrDir:(NSString *_Nullable)DataPathWithFileOrDir; 115 | 116 | +(id _Nullable ) BundlePathWithFileOrDir:(NSString *_Nullable)BundlePathWithFileOrDir; 117 | 118 | +(BOOL) PlistPath:(NSString *_Nullable)PlistPath RemoveObjectForKey:(id _Nullable )RemoveObjectForKey; 119 | 120 | +(NSArray *_Nullable) ContentOfDir:(NSString *_Nullable)ContentOfDir; 121 | 122 | +(NSString *_Nullable) SizeOfFolder:(NSString *_Nullable)sizeOfFolder; 123 | 124 | +(NSString *_Nullable)SizeOfFile:(NSString *_Nullable)SizeOfFile; 125 | 126 | +(NSString *_Nullable) GetUDID; 127 | 128 | +(UIButton *_Nullable) InitButtonWithName:(NSString *_Nullable)BuName Frame:(CGRect)frame InView:(UIView *_Nullable)View Target:(id _Nullable )Target Action:(SEL _Nullable )Action; 129 | 130 | +(UIButton *_Nullable) InitButtonWithName:(NSString *_Nullable)BuName LeftRight:(float)LeftRight UpDown:(float)UpDown Width:(float)Width Height:(float)Height InView:(UIView *_Nullable)View Target:(id _Nullable)Target Action:(SEL _Nullable )Action; 131 | 132 | +(UIView *_Nullable) InitViewWithBGColor:(UIColor *_Nullable)BGColor Frame:(CGRect)Frame Blur:(BOOL)Blur BackgroundImage:(UIImage *_Nullable)BackgroundImage InView:(UIView *_Nullable)InView; 133 | 134 | +(UIView *_Nullable) InitViewWithBGColor:(UIColor *_Nullable)BGColor Frame:(CGRect)Frame BackgroundImage:(UIImage *_Nullable)BackgroundImage InView:(UIView *_Nullable)InView; 135 | 136 | +(UILabel *_Nullable) InitLabelWithName:(NSString *_Nullable)Name TextAlignment:(NSTextAlignment)TextAlignment LeftRight:(float)LeftRight UpDown:(float)UpDown Width:(float)Width Height:(float)Height InView:(UIView *_Nullable)InView; 137 | 138 | +(UILabel *_Nullable) InitLabelWithName:(NSString *_Nullable)Name Frame:(CGRect)frame InView:(UIView *_Nullable)InView; 139 | 140 | +(UILabel *_Nullable) InitLabelInsideViewWithName:(NSString *_Nullable)Name TextAlignment:(NSTextAlignment)TextAlignment TextColor:(UIColor *_Nullable)TextColor LeftRight:(float)LeftRight UpDown:(float)UpDown Width:(float)Width Height:(float)Height InView:(UIView *_Nullable)InView; 141 | 142 | +(UIButton *_Nullable) InitButtonInsideViewWithName:(NSString *_Nullable)BuName LeftRight:(float)LeftRight UpDown:(float)UpDown Width:(float)Width Height:(float)Height InView:(UIView *_Nullable)View Target:(id _Nullable)Target Action:(SEL _Nullable )Action; 143 | 144 | 145 | //+(void) InitAlertWithTitle:(NSString *_Nullable)Title Message:(NSString *_Nullable)Message Buttons:(NSArray *_Nullable)Buttons CancelButtonTitle:(NSString *_Nullable)CancelButtonTitle AlertStyle:(UIAlertControllerStyle)AlertStyle handler:(void(^_Nullable)(NSString * _Nullable ButtonTitle))handler; 146 | 147 | 148 | +(UIImage *)RoundedImage:(UIImage *) image radius:(float)radius; 149 | 150 | 151 | +(void) InitAlertWithTitle:(NSString *_Nullable)Title TitleColor:(UIColor *_Nullable)TitleColor TitleImage:(UIImage *)TitleImage TitleImageFrame:(CGRect)TitleImageFrame Message:(NSString *_Nullable)Message MessageColor:(UIColor *_Nullable)MessageColor Buttons:(NSArray *_Nullable)Buttons CancelButtonTitle:(NSString *_Nullable)CancelButtonTitle ButtonsColor:(UIColor *_Nullable)ButtonsColor ButtonsImage:(UIImage *_Nullable)ButtonsImage BackgroundColor:(UIColor *_Nullable)BackgroundColor AlertStyle:(UIAlertControllerStyle)AlertStyle handler:(void(^_Nullable)(NSString * _Nullable ButtonTitle))handler; 152 | 153 | 154 | 155 | +(void) InitAlertInKeyWindowWithTitle:(NSString *_Nullable)Title Message:(NSString *_Nullable)Message Buttons:(NSArray *_Nullable)Buttons CancelButtonTitle:(NSString *_Nullable)CancelButtonTitle AlertStyle:(UIAlertControllerStyle)AlertStyle handler:(void(^_Nullable)(NSString * _Nullable ButtonTitle))handler; 156 | 157 | 158 | +(void) InitTextFieldAlertInKeyWindowWithTitle:(NSString *_Nullable)Title Message:(NSString *_Nullable)Message Buttons:(NSArray *_Nullable)Buttons CancelButtonTitle:(NSString *_Nullable)CancelButtonTitle handler:(void(^_Nullable)(NSString * _Nullable ButtonTitle, NSString * _Nullable Text))handler; 159 | 160 | 161 | +(UIImageView *_Nullable) InitImage:(UIImage *_Nullable)image LeftRight:(float)LeftRight UpDown:(float)UpDown Width:(float)Width Height:(float)Height InView:(UIView *_Nullable)InView; 162 | 163 | +(UIImageView *_Nullable) InitImage:(UIImage *_Nullable)image Frame:(CGRect)Frame InView:(UIView *_Nullable)InView; 164 | 165 | 166 | +(UIImage *_Nullable) BlureImage:(UIImage *_Nullable)image BlureLevel:(float)BlureLevel InView:(UIView *_Nullable)InView; 167 | 168 | 169 | +(UISwitch *_Nonnull) InitSwitchInsideViewWithAction:(SEL _Nullable )Action LeftRight:(float)LeftRight UpDown:(float)UpDown Width:(float)Width Height:(float)Height InView:(UIView *_Nullable)InView Target:(id _Nullable )Target; 170 | 171 | 172 | +(UIVisualEffectView *) BlurView:(UIView *_Nullable)View; 173 | 174 | 175 | +(NSString *_Nonnull) CheckDeviceType; 176 | 177 | 178 | +(BOOL) isIPhone_XS_MAX_XR_Screen; 179 | 180 | 181 | +(BOOL) isIPhone_X_XS_Screen; 182 | 183 | 184 | +(BOOL) isIPadScreen_12_9_inch; 185 | 186 | 187 | +(BOOL) isIPadScreen_Small; 188 | 189 | 190 | +(BOOL) isIPhone_7p_8p_Screen; 191 | 192 | 193 | +(BOOL) isIPhone_7_8_Screen; 194 | 195 | 196 | +(BOOL) isIPhone5Screen; 197 | 198 | 199 | 200 | +(void)ViewToBeAnimated:(UIView *_Nullable)views delegate:(id _Nullable)delegate Duration:(float)Duration StartAnimationFrom:(CATransitionSubtype _Nullable)StartAnimationFrom; 201 | 202 | 203 | +(UIScrollView *_Nullable) InitScrollViewWithBGColor:(UIColor *_Nullable)BGColor LeftRight:(float)LeftRight UpDown:(float)UpDown Width:(float)Width Height:(float)Height Delegate:(id _Nullable )Delegate InView:(UIView *_Nullable)InView; 204 | 205 | 206 | +(UIScrollView *_Nullable) InitScrollViewWithFrame:(CGRect)Frame BGColor:(UIColor *_Nullable)BGColor Delegate:(id _Nullable )Delegate InView:(UIView *_Nullable)InView; 207 | 208 | 209 | +(BOOL) isDirectory:(NSString *_Nullable)Path; 210 | 211 | 212 | +(UITextView *_Nullable) InitTextViewWithFrame:(CGRect)Frame BackgroundColor:(UIColor *_Nullable)BGColor TextColor:(UIColor *_Nullable)TextColor InView:(UIView *_Nullable)InView; 213 | 214 | 215 | +(UITextView *_Nullable) InitTextViewWithBGColor:(UIColor *_Nullable)BGColor TextColor:(UIColor *_Nullable)TextColor LeftRight:(float)LeftRight UpDown:(float)UpDown Width:(float)Width Height:(float)Height InView:(UIView *_Nullable)InView; 216 | 217 | 218 | 219 | 220 | +(void) InitTextFieldAlertWithTitle:(NSString *)Title Message:(NSString *)Message Buttons:(NSArray *)Buttons CancelButtonTitle:(NSString *)CancelButtonTitle handler:(void(^_Nullable)(NSString *ButtonTitle, NSString *Text, UITextField *TextField))handler; 221 | 222 | 223 | +(void) InitTextFieldAlertWithTitle:(NSString *_Nullable)Title TitleColor:(UIColor *_Nullable)TitleColor Message:(NSString *_Nullable)Message MessageColor:(UIColor *_Nullable)MessageColor Buttons:(NSArray *_Nullable)Buttons ButtonsColor:(UIColor *_Nullable)ButtonsColor ButtonsImage:(UIImage *_Nullable)ButtonsImage BackgroundColor:(UIColor *_Nullable)BackgroundColor TextFieldBGColor:(UIColor *_Nullable)TextFieldBGColor TextFieldTextColor:(UIColor *_Nullable)TextFieldTextColor CancelButtonTitle:(NSString *_Nullable)CancelButtonTitle handler:(void(^_Nullable)(NSString * _Nullable ButtonTitle, NSString * _Nullable Text))handler; 224 | 225 | 226 | +(CGRect) AboveTabBarDownNavigationBar; 227 | 228 | 229 | +(CGRect) AboveTabBarDownNavigationController; 230 | 231 | +(CGRect) InMiddleOfView:(UIView *_Nullable)View; 232 | 233 | 234 | +(NSString *)TakeStringFromLeft:(NSString *)TakeStringFromLeft HowMuch:(NSUInteger)HowMuch; 235 | 236 | +(UINavigationController *_Nullable) InitNavigationControllerWithTitle:(NSString *_Nullable)Title TitleColor:(UIColor *_Nullable)TitleColor RightButtonTitle:(NSString *_Nullable)RightButtonTitle RightButtonAction:(SEL _Nullable )RightButtonAction LeftButtonImage:(NSString *_Nullable)LeftButtonImage LeftButtonAction:(SEL _Nullable)LeftButtonAction ButtonsColor:(UIColor *_Nullable)ButtonsColor BackgroundColor:(UIColor *_Nullable)BackgroundColor Target:(id _Nullable)Target InView:(UIView *_Nullable)InView; 237 | 238 | +(UINavigationController *_Nullable) InitNavigationControllerWithTitle:(NSString *_Nullable)Title TitleColor:(UIColor *_Nullable)TitleColor RightButtonTitle:(NSString *_Nullable)RightButtonTitle RightButtonAction:(SEL _Nullable )RightButtonAction LeftButtonImage:(NSString *_Nullable)LeftButtonImage LeftButtonAction:(SEL _Nullable)LeftButtonAction EditButtonTitle:(NSString *_Nullable)EditButtonTitle EditButtonAction:(SEL)EditButtonAction ButtonsColor:(UIColor *_Nullable)ButtonsColor BackgroundColor:(UIColor *_Nullable)BackgroundColor Target:(id _Nullable)Target InView:(UIView *_Nullable)InView; 239 | 240 | 241 | +(UITextField *_Nullable) InitTextFieldWithFrame:(CGRect)Frame TextColor:(UIColor *_Nullable)TextColor BackgroundColor:(UIColor *_Nullable)BackgroundColor InView:(UIView *_Nullable)InView; 242 | 243 | 244 | 245 | +(void) ResizeLayoutView:(UIView *_Nullable)View InView:(UIView *_Nullable)InView AnchorDirection:(id _Nullable)AnchorDirection Constant:(float)Constant; 246 | 247 | 248 | +(void) ResizeLayoutView:(UIView *_Nullable)View InView:(UIView *_Nullable)InView LeftAnchor:(id _Nullable)LeftAnchor LeftAnchorConstant:(float)LeftAnchorConstant RightAnchor:(id _Nullable)RightAnchor RightAnchorConstant:(float)RightAnchorConstant TopAnchor:(id _Nullable)TopAnchor TopAnchorConstant:(float)TopAnchorConstant BottomAnchor:(id _Nullable)BottomAnchor BottomAnchorConstant:(float)BottomAnchorConstant; 249 | 250 | 251 | +(UIActivityViewController *_Nullable) ShareItemAtPath:(NSString *_Nullable)Path InViewController:(UIViewController *_Nullable)InViewController; 252 | 253 | 254 | 255 | +(void) ActivateTheFollowingCodeAfter:(float)Sleep handler:(void(^_Nullable)(void))handler; 256 | 257 | 258 | +(void) StartDispatch:(void(^_Nullable)(void))StartDispatch EndDispath:(void(^_Nullable)(void))EndDispath; 259 | 260 | +(void) StartDispatch:(void(^_Nullable)(void))StartDispatch; 261 | 262 | +(void) AnimatedDismissView:(UIView *_Nullable)View Duration:(float)Duration Y:(float)DirectionY X:(float)DirectionX handler:(void(^_Nullable)(void))handler; 263 | 264 | 265 | 266 | +(void) Start_Main_Thread_Dispatch:(void(^_Nullable)(void))StartDispatch; 267 | 268 | +(UIPasteboard *_Nullable) CopyToClipboard:(id _Nullable)Copy; 269 | 270 | 271 | +(NSString *_Nullable) PasteFromClipboard; 272 | 273 | 274 | +(UIWindow *_Nullable) NewWindowWithView:(UIView *_Nullable)View; 275 | 276 | 277 | +(void) DismissView:(id _Nullable)View; 278 | 279 | 280 | +(UIMenuController *_Nullable) InitMenuItemWithTitle:(NSString *_Nullable)Title InView:(UIView *_Nullable)InView Action:(SEL)Action; 281 | 282 | 283 | +(NSString *_Nullable) ShortenURL:(NSString *_Nullable)URL; 284 | 285 | 286 | 287 | +(void) RenameItemAtPath:(NSString *_Nullable)Path NewName:(NSString *_Nullable)NewName; 288 | 289 | 290 | 291 | 292 | +(AVPlayer *) PlayVideoAtPath:(NSURL *_Nullable)Path InViewController:(id _Nullable)ViewController; 293 | 294 | 295 | +(UISwitch *_Nonnull) InitSwitchAction:(SEL _Nullable )Action Frame:(CGRect)Frame InView:(UIView *_Nullable)InView Target:(id _Nullable )Target; 296 | 297 | 298 | +(void) PlayAudioAtPath:(NSString *_Nullable)Path; 299 | 300 | 301 | +(UIWindow *) InitWindowWithFrame:(CGRect)Frame; 302 | 303 | 304 | +(void) PlayAudioFromURL:(NSString *_Nullable)URL; 305 | 306 | 307 | 308 | +(CGRect) AboveTabBar; 309 | 310 | 311 | 312 | 313 | +(UIToolbar *) AddButtonOnKeyboardWithStyle:(UIBarButtonSystemItem)Style ShowOnTextField:(UITextField *)ShowOnTextField Target:(id)Target Action:(SEL)Action; 314 | 315 | 316 | 317 | 318 | +(UIViewController *) NewViewControllerInView:(UIView *)InView; 319 | 320 | 321 | +(BOOL) isDataPath:(NSString *)Path; 322 | 323 | 324 | 325 | +(UITapGestureRecognizer *) InitTapGestureRecognizerInView:(UIView *)InView NumberOfTapsRequired:(NSUInteger)TapsRequired NumberOfTouchesRequired:(NSUInteger)TouchesRequired Target:(id)Target Actions:(SEL)Action; 326 | 327 | 328 | +(UILongPressGestureRecognizer *) InitLongPressGestureRecognizerInView:(UIView *)InView PressDuration:(float)PressDuration NumberOfTouchesRequired:(NSUInteger)TouchesRequired Target:(id)Target Actions:(SEL)Action; 329 | 330 | 331 | +(UISwipeGestureRecognizer *) InitSwipeGestureRecognizerInView:(UIView *)InView setDirection:(UISwipeGestureRecognizerDirection)Direction NumberOfTouchesRequired:(NSUInteger)TouchesRequired Target:(id)Target Actions:(SEL)Action; 332 | 333 | 334 | +(NSString *) GetDataPathForBundleID:(NSString *)Bundle; 335 | 336 | 337 | +(NSString *) GetBundlePathForBundleID:(NSString *)Bundle; 338 | 339 | 340 | +(void) MoveableViewInView:(UIView *)InView Sender:(UIPanGestureRecognizer *)Sender Delegate:(id)Delegate; 341 | 342 | 343 | +(UIPanGestureRecognizer *) InitPanGestureRecognizerOnObject:(id)Object Target:(id)Target Action:(SEL)Action; 344 | 345 | 346 | +(void) AnimatedDismissView:(UIView *_Nullable)View StartAnimationFrom:(CATransitionSubtype _Nullable)StartAnimationFrom Duration:(float)Duration handler:(void(^_Nullable)(void))handler; 347 | 348 | 349 | 350 | +(UIView *_Nullable) InitViewWithFrame:(CGRect)Frame InView:(UIView *_Nullable)InView; 351 | 352 | @end 353 | 354 | 355 | 356 | static UIViewController *_topMostController(UIViewController *cont) { 357 | UIViewController *topController = cont; 358 | while (topController.presentedViewController) { 359 | topController = topController.presentedViewController; 360 | } 361 | if ([topController isKindOfClass:[UINavigationController class]]) { 362 | UIViewController *visible = ((UINavigationController *)topController).visibleViewController; 363 | if (visible) { 364 | topController = visible; 365 | } 366 | } 367 | return (topController != cont ? topController : nil); 368 | } 369 | static UIViewController *topMostController() { 370 | UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController; 371 | UIViewController *next = nil; 372 | while ((next = _topMostController(topController)) != nil) { 373 | topController = next; 374 | } 375 | return topController; 376 | } 377 | 378 | 379 | -------------------------------------------------------------------------------- /Tweak.xm: -------------------------------------------------------------------------------- 1 | // By @CrazyMind90 2 | 3 | #import 4 | #import 5 | #import "CMManager.h" 6 | #import 7 | #import 8 | 9 | 10 | #pragma GCC diagnostic ignored "-Wunused-variable" 11 | #pragma GCC diagnostic ignored "-Wprotocol" 12 | #pragma GCC diagnostic ignored "-Wmacro-redefined" 13 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 14 | #pragma GCC diagnostic ignored "-Wincomplete-implementation" 15 | #pragma GCC diagnostic ignored "-Wunknown-pragmas" 16 | #pragma GCC diagnostic ignored "-Wformat" 17 | #pragma GCC diagnostic ignored "-Wunknown-warning-option" 18 | #pragma GCC diagnostic ignored "-Wincompatible-pointer-types" 19 | 20 | 21 | 22 | 23 | 24 | @interface UIWindow (OSLogger) 25 | 26 | -(void) BeOSLogger; 27 | -(void) Movable_View:(UIPanGestureRecognizer *)Sender; 28 | -(void) Button_Tapped; 29 | -(void) InitOSLogger; 30 | -(void) C; 31 | -(void) DismissBaseView; 32 | -(void) OSLoggerNotification:(NSNotification *)Notification; 33 | -(void) Clear; 34 | -(void) DisOSLogger; 35 | -(void) Scroll_TableView_Down; 36 | -(UITableView *_Nullable) InitTableViewWithObjects:(NSArray *_Nullable)Objects Frame:(CGRect)Frame BackgroundColor:(UIColor *_Nullable)BGColor SeparatorColor:(UIColor *_Nullable)SepColor InView:(UIView *_Nullable)InView delegate:(id _Nullable )delegate; 37 | -(void) CopyAlert; 38 | @end 39 | 40 | UILabel *NotificationsLabel; 41 | UIImageView *ImageView; 42 | UIView *ViewCont; 43 | UITextView *TextView; 44 | UIViewController *View_Controller; 45 | UIView *BasicView; 46 | NSString *TextHolder = nil; 47 | BOOL isBaseViewPresented = NO; 48 | BOOL isOSLoggerPresented = NO; 49 | UIButton *RecordButton; 50 | BOOL isRecording = YES; 51 | UITableView *TableView; 52 | NSMutableArray *MutArray; 53 | 54 | %hookf(void , NSLog, NSString *_Nullable format, ...) { 55 | 56 | if (isOSLoggerPresented && format) { 57 | 58 | va_list ap; 59 | va_start(ap, format); 60 | 61 | NSString *iLogArgs = [[NSString alloc] initWithFormat:format arguments:ap]; 62 | 63 | if (isRecording) 64 | [[NSNotificationCenter defaultCenter] postNotificationName:@"OSLoggerNotification" object:iLogArgs]; 65 | 66 | va_end(ap); 67 | } 68 | 69 | } 70 | 71 | 72 | // %hookf(int , printf, const char *restricts, ...) { 73 | 74 | // if (isOSLoggerPresented && restricts) { 75 | 76 | // va_list arglist; 77 | // va_start( arglist, restricts ); 78 | // char *target = strdup(restricts); 79 | // vsprintf( &target[0], restricts, arglist ); 80 | // va_end( arglist ); 81 | 82 | // NSLog(@"%@",@(target)); 83 | 84 | // } 85 | 86 | // return %orig(restricts); 87 | // } 88 | 89 | 90 | 91 | NSArray *reArrangeArrays(NSArray *iObjects) { 92 | 93 | NSMutableArray *Words = [[NSMutableArray alloc] init]; 94 | NSMutableArray *Colors = [[NSMutableArray alloc] init]; 95 | 96 | CFIndex OneThree = 0; 97 | CFIndex TwoFour = 1; 98 | for (CFIndex iCounter = 0; iCounter < iObjects.count; iCounter ++) { 99 | 100 | [Words addObject:[iObjects objectAtIndex:OneThree]]; 101 | [Colors addObject:[iObjects objectAtIndex:TwoFour]]; 102 | 103 | OneThree = OneThree + 2; 104 | TwoFour = TwoFour + 2; 105 | 106 | if (OneThree > iObjects.count || TwoFour > iObjects.count) 107 | break; 108 | } 109 | 110 | return @[[NSArray arrayWithArray:Words],[NSArray arrayWithArray:Colors]]; 111 | } 112 | 113 | NSMutableAttributedString *Colorizer(NSString *OriginalText,NSArray *WordsAndColors,UIColor *TheRestColor) { 114 | 115 | NSArray *Text = [reArrangeArrays(WordsAndColors) objectAtIndex:0]; 116 | NSArray *Color = [reArrangeArrays(WordsAndColors) objectAtIndex:1]; 117 | 118 | NSMutableAttributedString *MutableAttString = [[NSMutableAttributedString alloc] initWithString:OriginalText attributes:@{NSForegroundColorAttributeName : TheRestColor}]; 119 | 120 | NSString *text = OriginalText; 121 | 122 | if (OriginalText != nil) { 123 | 124 | for (NSUInteger Counter = 0; Counter < Color.count; Counter ++) { 125 | 126 | NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:[NSString stringWithFormat:@"(%@)",[Text objectAtIndex:Counter]] options:kNilOptions error:nil]; 127 | 128 | NSRange range = NSMakeRange(0 ,text.length); 129 | 130 | [regex enumerateMatchesInString:text options:kNilOptions range:range usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) { 131 | 132 | NSRange subStringRange = [result rangeAtIndex:0]; 133 | 134 | [MutableAttString addAttribute:NSForegroundColorAttributeName value:[Color objectAtIndex:Counter] range:subStringRange]; 135 | 136 | }]; 137 | 138 | 139 | } 140 | } 141 | return MutableAttString; 142 | } 143 | 144 | 145 | %hook UIWindow 146 | %new 147 | - (void) OSLoggerNotification:(NSNotification *)Notification { 148 | 149 | if ([[Notification name] isEqual:@"OSLoggerNotification"]) { 150 | 151 | dispatch_async(dispatch_get_main_queue(), ^{ 152 | 153 | if (!isBaseViewPresented) { 154 | NotificationsLabel.text = [NSString stringWithFormat:@"%li",(CFIndex)NotificationsLabel.text.integerValue + 1] ? : @"1"; 155 | NotificationsLabel.hidden = NO; 156 | } 157 | 158 | [MutArray addObject:[Notification object]]; 159 | [TableView reloadData]; 160 | 161 | [self Scroll_TableView_Down]; 162 | 163 | }); 164 | } 165 | } 166 | 167 | %new 168 | -(void) Scroll_TableView_Down { 169 | 170 | if (MutArray.count > 0) 171 | [TableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:MutArray.count-1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES]; 172 | 173 | } 174 | 175 | 176 | - (void)_resizeWindowToFullScreenIfNecessary { 177 | 178 | %orig; 179 | 180 | [CMManager InitLongPressGestureRecognizerInView:self PressDuration:1.0 NumberOfTouchesRequired:2 Target:self Actions:@selector(BeOSLogger)]; 181 | 182 | } 183 | 184 | 185 | 186 | 187 | %new 188 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 189 | 190 | 191 | return MutArray.count; 192 | } 193 | 194 | %new 195 | -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 196 | 197 | NSIndexPath *Path = TableView.indexPathForSelectedRow; 198 | NSString *SelectedRow = MutArray[Path.row]; 199 | 200 | [self CopyAlert]; 201 | 202 | [CMManager CopyToClipboard:(UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath].textLabel.text]; 203 | 204 | [self performSelector:@selector(Reloader) withObject:nil afterDelay:0.1f]; 205 | 206 | } 207 | 208 | %new 209 | -(void) Reloader { 210 | 211 | [TableView reloadData]; 212 | } 213 | 214 | 215 | 216 | BOOL Colorize = NO; 217 | %new 218 | -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 219 | 220 | static NSString *CellID = @"Cell"; 221 | 222 | UITableViewCell *Cell; 223 | 224 | Cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellID]; 225 | 226 | tableView.backgroundColor = UIColor.clearColor; 227 | 228 | Cell.textLabel.text = MutArray[indexPath.row]; 229 | 230 | Cell.textLabel.textColor = UIColorFromHEX(0xFFFFFF); 231 | 232 | Cell.textLabel.numberOfLines = 0; 233 | 234 | if (Colorize) { 235 | Cell.backgroundColor = UIColorFromHEX(0x070707); 236 | Colorize = NO; 237 | } else if (!Colorize) { 238 | Cell.backgroundColor = UIColorFromHEX(0x212121); 239 | Colorize = YES; 240 | } 241 | 242 | 243 | if ([Cell.textLabel.text containsString:@"OSLogger"]) 244 | Cell.textLabel.attributedText = Colorizer(Cell.textLabel.text,@[Cell.textLabel.text,UIColor.yellowColor], UIColor.whiteColor); 245 | 246 | 247 | return Cell; 248 | } 249 | 250 | 251 | %new 252 | -(UITableView *_Nullable) InitTableViewWithObjects:(NSArray *_Nullable)Objects Frame:(CGRect)Frame BackgroundColor:(UIColor *_Nullable)BGColor SeparatorColor:(UIColor *_Nullable)SepColor InView:(UIView *_Nullable)InView delegate:(id _Nullable )delegate { 253 | 254 | TableView = [[UITableView alloc] initWithFrame:Frame style:UITableViewStyleGrouped]; 255 | 256 | 257 | TableView.backgroundColor = BGColor; 258 | TableView.separatorColor = SepColor; 259 | TableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 260 | TableView.delegate = delegate; 261 | TableView.dataSource = delegate; 262 | 263 | [InView addSubview:TableView]; 264 | 265 | 266 | return TableView; 267 | 268 | } 269 | 270 | 271 | %new 272 | -(void) BeOSLogger { 273 | 274 | if (!isOSLoggerPresented) { 275 | 276 | MutArray = [[NSMutableArray alloc] init]; 277 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(OSLoggerNotification:) name:@"OSLoggerNotification" object:nil]; 278 | 279 | ViewCont = [CMManager InitViewWithBGColor:UIColor.clearColor Frame:CGRectNull BackgroundImage:nil InView:topMostController().view]; 280 | 281 | ViewCont.clipsToBounds = YES; 282 | ViewCont.alpha = 0.9f; 283 | ViewCont.backgroundColor = UIColor.clearColor; 284 | 285 | [ViewCont setTranslatesAutoresizingMaskIntoConstraints:NO]; 286 | [NSLayoutConstraint activateConstraints:@[ 287 | 288 | [ViewCont.topAnchor constraintEqualToAnchor:topMostController().view.topAnchor constant:215], 289 | [ViewCont.leadingAnchor constraintEqualToAnchor:topMostController().view.leadingAnchor constant:5], 290 | [ViewCont.trailingAnchor constraintEqualToAnchor:topMostController().view.leadingAnchor constant:75], 291 | [ViewCont.bottomAnchor constraintEqualToAnchor:topMostController().view.topAnchor constant:285], 292 | 293 | ]]; 294 | 295 | NSArray *Obj = [CMManager InitButtonImage:[UIImage imageNamed:@"/Library/Application Support/OSLogger.bundle/OSL.png"] InView:ViewCont Target:self Action:@selector(Button_Tapped)]; 296 | 297 | ImageView = [Obj objectAtIndex:1]; 298 | ImageView.clipsToBounds = YES; 299 | ImageView.layer.cornerRadius = 35; 300 | ImageView.alpha = 0.7f; 301 | 302 | [ImageView setTranslatesAutoresizingMaskIntoConstraints:NO]; 303 | [NSLayoutConstraint activateConstraints:@[ 304 | 305 | [ImageView.topAnchor constraintEqualToAnchor:ViewCont.topAnchor constant:0], 306 | [ImageView.leadingAnchor constraintEqualToAnchor:ViewCont.leadingAnchor constant:0], 307 | [ImageView.trailingAnchor constraintEqualToAnchor:ViewCont.trailingAnchor constant:0], 308 | [ImageView.bottomAnchor constraintEqualToAnchor:ViewCont.bottomAnchor constant:0], 309 | 310 | ]]; 311 | 312 | NotificationsLabel = [CMManager InitLabelWithName:@"0" Frame:CGRectNull InView:ViewCont]; 313 | NotificationsLabel.hidden = YES; 314 | NotificationsLabel.clipsToBounds = YES; 315 | NotificationsLabel.layer.cornerRadius = 12; 316 | NotificationsLabel.alpha = 0.6f; 317 | NotificationsLabel.layer.backgroundColor = UIColor.redColor.CGColor; 318 | NotificationsLabel.textAlignment = NSTextAlignmentCenter; 319 | NotificationsLabel.font = [UIFont systemFontOfSize:15]; 320 | NotificationsLabel.numberOfLines = 1; 321 | NotificationsLabel.minimumScaleFactor = 0.01; 322 | NotificationsLabel.adjustsFontSizeToFitWidth = YES; 323 | 324 | 325 | [NotificationsLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; 326 | [NSLayoutConstraint activateConstraints:@[ 327 | 328 | [NotificationsLabel.topAnchor constraintEqualToAnchor:ViewCont.topAnchor constant:0], 329 | [NotificationsLabel.leadingAnchor constraintEqualToAnchor:ViewCont.leadingAnchor constant:0], 330 | [NotificationsLabel.trailingAnchor constraintEqualToAnchor:ViewCont.leadingAnchor constant:25], 331 | [NotificationsLabel.bottomAnchor constraintEqualToAnchor:ViewCont.topAnchor constant:25], 332 | 333 | ]]; 334 | 335 | [CMManager InitLongPressGestureRecognizerInView:[Obj objectAtIndex:0] PressDuration:0.30 NumberOfTouchesRequired:1 Target:self Actions:@selector(DisOSLogger)]; 336 | 337 | [CMManager InitPanGestureRecognizerOnObject:ViewCont Target:self Action:@selector(Movable_View:)]; 338 | 339 | isOSLoggerPresented = YES; 340 | isRecording = YES; 341 | 342 | } 343 | } 344 | 345 | %new 346 | -(void) DisOSLogger { 347 | 348 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 349 | 350 | [self DismissBaseView]; 351 | 352 | [ViewCont setHidden:YES]; 353 | [ViewCont removeFromSuperview]; 354 | 355 | NotificationsLabel.text = @""; 356 | NotificationsLabel.hidden = YES; 357 | 358 | isOSLoggerPresented = NO; 359 | 360 | } 361 | 362 | %new 363 | -(void) Movable_View:(UIPanGestureRecognizer *)Sender { 364 | 365 | if (Sender.state == UIGestureRecognizerStateBegan) 366 | ImageView.alpha = 0.9f; 367 | 368 | if (Sender.state == UIGestureRecognizerStateEnded) 369 | ImageView.alpha = 0.5f; 370 | 371 | [CMManager MoveableViewInView:topMostController().view Sender:Sender Delegate:self]; 372 | 373 | } 374 | 375 | 376 | %new 377 | -(void) Button_Tapped { 378 | 379 | NotificationsLabel.text = @"0"; 380 | NotificationsLabel.hidden = YES; 381 | 382 | isBaseViewPresented ? [self DismissBaseView] : [self InitOSLogger]; 383 | 384 | } 385 | 386 | %new 387 | -(void) InitOSLogger { 388 | 389 | if (!isBaseViewPresented) { 390 | BasicView = [CMManager InitViewWithBGColor:UIColor.clearColor Frame:CGRectNull BackgroundImage:nil InView:topMostController().view]; 391 | 392 | BasicView.clipsToBounds = YES; 393 | BasicView.layer.cornerRadius = 31; 394 | BasicView.alpha = 0.9f; 395 | [BasicView setTranslatesAutoresizingMaskIntoConstraints:NO]; 396 | [NSLayoutConstraint activateConstraints:@[ 397 | 398 | [BasicView.topAnchor constraintEqualToAnchor:topMostController().view.centerYAnchor constant:-230], 399 | [BasicView.leadingAnchor constraintEqualToAnchor:topMostController().view.centerXAnchor constant:-160], 400 | [BasicView.trailingAnchor constraintEqualToAnchor:topMostController().view.centerXAnchor constant:160], 401 | [BasicView.bottomAnchor constraintEqualToAnchor:topMostController().view.centerYAnchor constant:230], 402 | 403 | ]]; 404 | 405 | [CMManager BlurView:BasicView]; 406 | 407 | 408 | [CMManager InitPanGestureRecognizerOnObject:BasicView Target:self Action:@selector(Movable_View:)]; 409 | 410 | NSArray *iOb = [CMManager InitButtonLabelWithName:@"OSLogger" InView:BasicView Target:self Action:@selector(C)]; 411 | 412 | UILabel *OSLoggerLabel = [iOb objectAtIndex:1]; 413 | OSLoggerLabel.textAlignment = NSTextAlignmentCenter; 414 | OSLoggerLabel.font = [UIFont boldSystemFontOfSize:20]; 415 | OSLoggerLabel.numberOfLines = 1; 416 | OSLoggerLabel.minimumScaleFactor = 0.01; 417 | OSLoggerLabel.adjustsFontSizeToFitWidth = YES; 418 | OSLoggerLabel.layer.backgroundColor = UIColorFromHEX(0x5478E4).CGColor; 419 | 420 | [OSLoggerLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; 421 | [NSLayoutConstraint activateConstraints:@[ 422 | 423 | [OSLoggerLabel.topAnchor constraintEqualToAnchor:BasicView.topAnchor constant:0], 424 | [OSLoggerLabel.leadingAnchor constraintEqualToAnchor:BasicView.leadingAnchor constant:0], 425 | [OSLoggerLabel.trailingAnchor constraintEqualToAnchor:BasicView.trailingAnchor constant:-70], 426 | [OSLoggerLabel.bottomAnchor constraintEqualToAnchor:BasicView.topAnchor constant:50], 427 | 428 | ]]; 429 | 430 | RecordButton = [CMManager InitButtonWithName:@"Recording" Frame:CGRectNull InView:BasicView Target:self Action:@selector(RecordState)]; 431 | 432 | if (isRecording) { 433 | RecordButton.layer.backgroundColor = UIColorFromHEX(0xE94E3D).CGColor; 434 | [RecordButton setTitle:@"Recording" forState:UIControlStateNormal]; 435 | } else { 436 | RecordButton.layer.backgroundColor = UIColorFromHEX(0x65BA4B).CGColor; 437 | [RecordButton setTitle:@"Start" forState:UIControlStateNormal]; 438 | } 439 | 440 | 441 | RecordButton.titleLabel.font = [UIFont systemFontOfSize:13]; 442 | 443 | [RecordButton setTranslatesAutoresizingMaskIntoConstraints:NO]; 444 | [NSLayoutConstraint activateConstraints:@[ 445 | 446 | [RecordButton.topAnchor constraintEqualToAnchor:BasicView.topAnchor constant:0], 447 | [RecordButton.leadingAnchor constraintEqualToAnchor:BasicView.trailingAnchor constant:-70], 448 | [RecordButton.trailingAnchor constraintEqualToAnchor:BasicView.trailingAnchor constant:0], 449 | [RecordButton.bottomAnchor constraintEqualToAnchor:BasicView.topAnchor constant:50], 450 | 451 | ]]; 452 | 453 | 454 | TableView = [self InitTableViewWithObjects:nil Frame:CGRectNull BackgroundColor:UIColor.clearColor SeparatorColor:UIColor.clearColor InView:BasicView delegate:self]; 455 | 456 | TableView.alpha = 0.7f; 457 | TableView.clipsToBounds = YES; 458 | TableView.layer.cornerRadius = 31; 459 | TableView.layer.maskedCorners = kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner; 460 | 461 | [TableView setTranslatesAutoresizingMaskIntoConstraints:NO]; 462 | [NSLayoutConstraint activateConstraints:@[ 463 | 464 | [TableView.topAnchor constraintEqualToAnchor:OSLoggerLabel.bottomAnchor constant:0], 465 | [TableView.leadingAnchor constraintEqualToAnchor:BasicView.leadingAnchor constant:0], 466 | [TableView.trailingAnchor constraintEqualToAnchor:BasicView.trailingAnchor constant:0], 467 | [TableView.bottomAnchor constraintEqualToAnchor:BasicView.bottomAnchor constant:0], 468 | 469 | ]]; 470 | 471 | [CMManager ActivateTheFollowingCodeAfter:0.10 handler:^{ 472 | [self Scroll_TableView_Down]; 473 | }]; 474 | 475 | UIButton *ClearButton = [CMManager InitButtonWithName:@"C" Frame:CGRectNull InView:BasicView Target:self Action:@selector(Clear)]; 476 | 477 | ClearButton.layer.backgroundColor = UIColorFromHEX(0x656565).CGColor; 478 | ClearButton.layer.cornerRadius = 30; 479 | ClearButton.layer.maskedCorners = kCALayerMinXMinYCorner; 480 | ClearButton.alpha = 0.7f; 481 | 482 | [ClearButton setTranslatesAutoresizingMaskIntoConstraints:NO]; 483 | [NSLayoutConstraint activateConstraints:@[ 484 | 485 | [ClearButton.topAnchor constraintEqualToAnchor:BasicView.bottomAnchor constant:-43], 486 | [ClearButton.leadingAnchor constraintEqualToAnchor:BasicView.trailingAnchor constant:-43], 487 | [ClearButton.trailingAnchor constraintEqualToAnchor:BasicView.trailingAnchor constant:5], 488 | [ClearButton.bottomAnchor constraintEqualToAnchor:BasicView.bottomAnchor constant:5], 489 | 490 | ]]; 491 | 492 | isBaseViewPresented = YES; 493 | } 494 | 495 | } 496 | 497 | %new 498 | -(void) RecordState { 499 | 500 | if (isRecording) { 501 | 502 | RecordButton.layer.backgroundColor = UIColorFromHEX(0x65BA4B).CGColor; 503 | [RecordButton setTitle:@"Start" forState:UIControlStateNormal]; 504 | isRecording = NO; 505 | } else { 506 | 507 | RecordButton.layer.backgroundColor = UIColorFromHEX(0xE94E3D).CGColor; 508 | [RecordButton setTitle:@"Recording" forState:UIControlStateNormal]; 509 | isRecording = YES; 510 | } 511 | 512 | } 513 | 514 | %new 515 | -(void) Clear { 516 | 517 | [MutArray removeAllObjects]; 518 | [TableView reloadData]; 519 | } 520 | 521 | %new 522 | -(void) C { 523 | 524 | [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://twitter.com/CrazyMind90"] options:@{} completionHandler:nil]; 525 | } 526 | 527 | %new 528 | -(void) DismissBaseView { 529 | 530 | isBaseViewPresented = NO; 531 | [CMManager AnimatedDismissView:BasicView StartAnimationFrom:kCATransitionFade Duration:0.30 handler:^{ 532 | 533 | }]; 534 | 535 | } 536 | 537 | 538 | %new 539 | -(void) CopyAlert { 540 | 541 | UILabel *CopyLabelView = [CMManager InitLabelWithName:@"Copied" Frame:CGRectNull InView:topMostController().view]; 542 | 543 | CopyLabelView.textAlignment = NSTextAlignmentCenter; 544 | CopyLabelView.textColor = UIColor.whiteColor; 545 | CopyLabelView.font = [UIFont systemFontOfSize:20]; 546 | CopyLabelView.layer.backgroundColor = UIColorFromHEX(0x252525).CGColor; 547 | CopyLabelView.clipsToBounds = YES; 548 | CopyLabelView.layer.cornerRadius = 10; 549 | 550 | [CopyLabelView setTranslatesAutoresizingMaskIntoConstraints:NO]; 551 | 552 | [NSLayoutConstraint activateConstraints:@[ 553 | 554 | [CopyLabelView.topAnchor constraintEqualToAnchor:topMostController().view.topAnchor constant:50], 555 | [CopyLabelView.leadingAnchor constraintEqualToAnchor:topMostController().view.centerXAnchor constant:-50], 556 | [CopyLabelView.trailingAnchor constraintEqualToAnchor:topMostController().view.centerXAnchor constant:50], 557 | [CopyLabelView.bottomAnchor constraintEqualToAnchor:topMostController().view.topAnchor constant:90], 558 | 559 | ]]; 560 | 561 | [CMManager ViewToBeAnimated:CopyLabelView delegate:self Duration:0.35 StartAnimationFrom:kCATransitionFromBottom]; 562 | 563 | [CMManager ActivateTheFollowingCodeAfter:2 handler:^{ 564 | 565 | [CMManager AnimatedDismissView:CopyLabelView StartAnimationFrom:kCATransitionFromTop Duration:0.35 handler:^{ 566 | 567 | }]; 568 | }]; 569 | } 570 | 571 | %end 572 | 573 | 574 | -------------------------------------------------------------------------------- /CMManager.m: -------------------------------------------------------------------------------- 1 | // By @CrazyMind90 2 | 3 | #pragma GCC diagnostic ignored "-Wunused-variable" 4 | #pragma GCC diagnostic ignored "-Wprotocol" 5 | #pragma GCC diagnostic ignored "-Wmacro-redefined" 6 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 7 | #pragma GCC diagnostic ignored "-Wincomplete-implementation" 8 | 9 | #import "CMManager.h" 10 | 11 | 12 | 13 | @implementation CMManager 14 | 15 | 16 | +(UIMenu *) InitMenuOnButton:(UIButton *)Button MenuTitles:(NSArray *)MenuTitles ActionsTitles:(NSArray *)ActionsTitles ImagesNames:(NSArray *)ImagesNames Target:(id)Target Action:(SEL)Action handler:(void(^_Nullable)(NSString *ButtonTitle))handler { 17 | 18 | UIMenu *Menu = [UIMenu alloc]; 19 | NSMutableArray *Obj = [[NSMutableArray alloc] init]; 20 | 21 | for (CFIndex iCounter = 0; iCounter < ActionsTitles.count; iCounter ++) { 22 | 23 | for (NSString *EachImageName in ImagesNames) { 24 | 25 | UIAction *Action0 = [UIAction actionWithTitle:[ActionsTitles objectAtIndex:iCounter] image:[UIImage imageNamed:EachImageName] identifier:[ActionsTitles objectAtIndex:iCounter] handler:^(__kindof UIAction * _Nonnull action) { 26 | 27 | handler(action.title); 28 | }]; 29 | 30 | [Obj addObject:Action0]; 31 | 32 | } 33 | 34 | } 35 | 36 | for (NSString *EachMenuTitle in MenuTitles) { 37 | 38 | Menu = [UIMenu menuWithTitle:EachMenuTitle children:[NSArray arrayWithArray:Obj]]; 39 | 40 | Button.menu = Menu; 41 | Button.showsMenuAsPrimaryAction = YES; 42 | [Button addTarget:Target action:Action forControlEvents:UIControlEventAllEvents]; 43 | 44 | return Menu; 45 | } 46 | 47 | return Menu; 48 | } 49 | 50 | 51 | +(void) InitAlertWithTitle:(NSString *_Nullable)Title Message:(NSString *_Nullable)Message Buttons:(NSArray *_Nullable)Buttons CancelButtonTitle:(NSString *_Nullable)CancelButtonTitle AlertStyle:(UIAlertControllerStyle)AlertStyle handler:(void(^_Nullable)(NSString * _Nullable ButtonTitle, NSUInteger index))handler { 52 | 53 | 54 | 55 | UIAlertController *alert = [UIAlertController alertControllerWithTitle:Title message:Message preferredStyle:AlertStyle]; 56 | 57 | NSUInteger Counter = 0; 58 | for (NSString *EachButton in Buttons) { 59 | 60 | UIAlertAction *action = [UIAlertAction actionWithTitle:EachButton style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 61 | 62 | handler(action.title,Counter); 63 | 64 | 65 | 66 | }]; 67 | 68 | 69 | [alert addAction:action]; 70 | Counter ++; 71 | 72 | } 73 | 74 | 75 | if (!(CancelButtonTitle == NULL)) { 76 | 77 | UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:CancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { 78 | 79 | 80 | }]; 81 | 82 | //CancelColor 83 | [cancelAction setValue:UIColor.redColor forKey:@"titleTextColor"]; 84 | [alert addAction:cancelAction]; 85 | 86 | } 87 | 88 | [topMostController() presentViewController:alert animated:true completion:nil]; 89 | 90 | 91 | } 92 | 93 | 94 | +(void) ActiveThisCodeOneTime:(void (^_Nullable) (void) ) handler { 95 | 96 | 97 | static BOOL DidActive = NO; 98 | 99 | if (!DidActive) { 100 | 101 | handler(); 102 | 103 | DidActive = YES; 104 | 105 | } 106 | 107 | } 108 | 109 | 110 | +(void) ActivateThisCodeForTimes:(NSUInteger)Times handler:(void (^_Nullable) (void) )handler { 111 | 112 | Times -= 1; 113 | [CMManager ActiveThisCodeOneTime:^{ 114 | 115 | 116 | 117 | for (NSUInteger Counter = 0; Counter <= Times; Counter ++) { 118 | 119 | handler(); 120 | 121 | } 122 | 123 | 124 | }]; 125 | } 126 | 127 | 128 | +(void) ForLoop:(NSMutableArray *)Array Handler:(void (^_Nullable) (NSUInteger Counter) )handler { 129 | 130 | 131 | 132 | for (NSUInteger Co = 0; Co < Array.count; Co ++) { 133 | 134 | handler(Co); 135 | 136 | 137 | } 138 | 139 | } 140 | 141 | 142 | +(void) AlertWithTitle:(NSString *)Title Message:(NSString *)Message ButtonTitle:(NSString *)ButtonTitle { 143 | 144 | UIAlertController *alert = [UIAlertController alertControllerWithTitle:Title message:Message preferredStyle:UIAlertControllerStyleAlert]; 145 | 146 | UIAlertAction *action = [UIAlertAction actionWithTitle:ButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 147 | 148 | }]; 149 | 150 | [alert addAction:action]; 151 | 152 | [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alert animated:true completion:nil]; 153 | 154 | 155 | } 156 | 157 | +(NSMutableAttributedString *) OriginalText:(NSString *)OriginalText ChangeColorOfText:(NSArray *)Text ToColor:(NSArray *)Color { 158 | 159 | 160 | NSMutableAttributedString *mutableAttributedString; 161 | 162 | NSString *text = OriginalText; 163 | 164 | if (OriginalText != nil) { 165 | 166 | mutableAttributedString = [[NSMutableAttributedString alloc] initWithString:OriginalText]; 167 | 168 | for (NSUInteger Counter = 0; Counter < Color.count; Counter ++) { 169 | 170 | NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:[NSString stringWithFormat:@"(%@)",[Text objectAtIndex:Counter]] options:kNilOptions error:nil]; 171 | 172 | NSRange range = NSMakeRange(0 ,text.length); 173 | 174 | [regex enumerateMatchesInString:text options:kNilOptions range:range usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) { 175 | 176 | NSRange subStringRange = [result rangeAtIndex:0]; 177 | 178 | [mutableAttributedString addAttribute:NSForegroundColorAttributeName value:[Color objectAtIndex:Counter] range:subStringRange]; 179 | 180 | }]; 181 | 182 | 183 | } 184 | } 185 | 186 | 187 | return mutableAttributedString; 188 | } 189 | 190 | 191 | +(NSString *) GetDataPathForBundleID:(NSString *)Bundle { 192 | 193 | NSString *BundleID; 194 | 195 | 196 | NSString *Applications = @"/var/mobile/Containers/Data/Application"; 197 | NSArray *Content = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:Applications error:nil]; 198 | 199 | for (NSString *EachApp in Content) { 200 | 201 | NSString *Plist = [NSString stringWithFormat:@"%@/%@/.com.apple.mobile_container_manager.metadata.plist",Applications,EachApp]; 202 | 203 | NSMutableDictionary *MutDic = [[NSMutableDictionary alloc] initWithContentsOfFile:Plist]; 204 | 205 | NSString *Object = [MutDic objectForKey:@"MCMMetadataIdentifier"]; 206 | 207 | if ([Object isEqual:Bundle]) { 208 | 209 | BundleID = [NSString stringWithFormat:@"%@/%@",Applications,EachApp]; 210 | 211 | } 212 | 213 | } 214 | 215 | return BundleID; 216 | } 217 | 218 | 219 | 220 | 221 | 222 | +(NSString *) GetBundlePathForBundleID:(NSString *)Bundle { 223 | 224 | NSString *AppPath; 225 | 226 | NSString *Applications = @"/var/containers/Bundle/Application"; 227 | NSArray *Content = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:Applications error:nil]; 228 | 229 | for (NSString *EachApp in Content) { 230 | 231 | NSString *Plist = [NSString stringWithFormat:@"%@/%@/.com.apple.mobile_container_manager.metadata.plist",Applications,EachApp]; 232 | 233 | NSMutableDictionary *MutDic = [[NSMutableDictionary alloc] initWithContentsOfFile:Plist]; 234 | 235 | NSString *Object = [MutDic objectForKey:@"MCMMetadataIdentifier"]; 236 | 237 | if ([Object isEqual:Bundle]) { 238 | 239 | NSString *BundleID = [NSString stringWithFormat:@"%@/%@",Applications,EachApp]; 240 | 241 | 242 | 243 | for (NSString *Dot_App in [CMManager ContentOfDir:BundleID]) { 244 | 245 | NSString *InfoPath = [NSString stringWithFormat:@"%@/%@/Info.plist",BundleID,Dot_App]; 246 | 247 | NSString *Bundle = [CMManager PlistPath:InfoPath ObjectForKey:@"CFBundleIdentifier"]; 248 | 249 | if ([Bundle isEqual:Bundle]) 250 | AppPath = [InfoPath stringByDeletingLastPathComponent]; 251 | } 252 | 253 | 254 | } 255 | 256 | } 257 | 258 | return AppPath; 259 | } 260 | 261 | 262 | 263 | 264 | 265 | AVPlayer *Player; 266 | 267 | 268 | 269 | +(UIPanGestureRecognizer *) InitPanGestureRecognizerOnObject:(id)Object Target:(id)Target Action:(SEL)Action { 270 | 271 | UIPanGestureRecognizer *Pan = [[UIPanGestureRecognizer alloc] initWithTarget:Target action:Action]; 272 | 273 | [Object addGestureRecognizer:Pan]; 274 | 275 | return Pan; 276 | } 277 | 278 | 279 | +(void) MoveableViewInView:(UIView *)InView Sender:(UIPanGestureRecognizer *)Sender Delegate:(id)Delegate { 280 | 281 | [InView bringSubviewToFront:Sender.view]; 282 | CGPoint translatedPoint = [Sender translationInView:Sender.view.superview]; 283 | 284 | CGFloat firstX = 0; 285 | CGFloat firstY = 0; 286 | if (Sender.state == UIGestureRecognizerStateBegan) { 287 | firstX = Sender.view.center.x; 288 | firstY = Sender.view.center.y; 289 | } 290 | 291 | 292 | translatedPoint = CGPointMake(Sender.view.center.x+translatedPoint.x, Sender.view.center.y+translatedPoint.y); 293 | 294 | [Sender.view setCenter:translatedPoint]; 295 | [Sender setTranslation:CGPointZero inView:Sender.view]; 296 | 297 | if (Sender.state == UIGestureRecognizerStateEnded) { 298 | CGFloat velocityX = (0.2*[Sender velocityInView:InView].x); 299 | CGFloat velocityY = (0.2*[Sender velocityInView:InView].y); 300 | 301 | CGFloat finalX = translatedPoint.x + velocityX; 302 | CGFloat finalY = translatedPoint.y + velocityY;// translatedPoint.y + (.35*[(UIPanGestureRecognizer*)sender velocityInView:self.view].y); 303 | 304 | if (finalX < 0) { 305 | finalX = 0; 306 | } else if (finalX > InView.frame.size.width) { 307 | finalX = InView.frame.size.width; 308 | } 309 | 310 | if (finalY < 50) { // to avoid status bar 311 | finalY = 50; 312 | } else if (finalY > InView.frame.size.height) { 313 | finalY = InView.frame.size.height; 314 | } 315 | 316 | CGFloat animationDuration = (ABS(velocityX)*.0002)+.2; 317 | 318 | //NSLog(@"the duration is: %f", animationDuration); 319 | 320 | [UIView beginAnimations:nil context:NULL]; 321 | [UIView setAnimationDuration:animationDuration]; 322 | [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 323 | [UIView setAnimationDelegate:self]; 324 | // [UIView setAnimationDidStopSelector:@selector(animationDidFinish)]; 325 | [[Sender view] setCenter:CGPointMake(finalX, finalY)]; 326 | [UIView commitAnimations]; 327 | } 328 | 329 | } 330 | 331 | +(UIImage *_Nullable) GenerateThumbImageFromPath:(NSString *_Nullable)Path { 332 | 333 | NSURL *url = [NSURL fileURLWithPath:Path]; 334 | 335 | AVAsset *asset = [AVAsset assetWithURL:url]; 336 | AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]initWithAsset:asset]; 337 | imageGenerator.appliesPreferredTrackTransform = YES; 338 | CMTime time = [asset duration]; 339 | time.value = 1000; 340 | CGImageRef imageRef = [imageGenerator copyCGImageAtTime:time actualTime:NULL error:NULL]; 341 | UIImage *thumbnail = [UIImage imageWithCGImage:imageRef]; 342 | CGImageRelease(imageRef); 343 | 344 | return thumbnail; 345 | } 346 | 347 | 348 | +(UISwipeGestureRecognizer *) InitSwipeGestureRecognizerInView:(UIView *)InView setDirection:(UISwipeGestureRecognizerDirection)Direction NumberOfTouchesRequired:(NSUInteger)TouchesRequired Target:(id)Target Actions:(SEL)Action { 349 | 350 | UISwipeGestureRecognizer *Swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:Target action:Action]; 351 | 352 | [Swipe setDirection:Direction]; 353 | 354 | [InView addGestureRecognizer:Swipe]; 355 | [Swipe setNumberOfTouchesRequired:1]; 356 | 357 | 358 | return Swipe; 359 | 360 | 361 | 362 | // -(void) SwipGes:(UISwipeGestureRecognizer *)Sender { 363 | // 364 | // if (Sender.state == UIGestureRecognizerStateEnded) 365 | // //NSLog(@"UIGestureRecognizerStateEnded"); 366 | //} 367 | 368 | 369 | } 370 | 371 | 372 | +(UILongPressGestureRecognizer *) InitLongPressGestureRecognizerInView:(UIView *)InView PressDuration:(float)PressDuration NumberOfTouchesRequired:(NSUInteger)TouchesRequired Target:(id)Target Actions:(SEL)Action { 373 | 374 | UILongPressGestureRecognizer *LongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:Target action:Action]; 375 | 376 | LongPress.numberOfTouchesRequired = TouchesRequired; 377 | LongPress.minimumPressDuration = PressDuration; 378 | [InView addGestureRecognizer:LongPress]; 379 | 380 | 381 | return LongPress; 382 | 383 | } 384 | 385 | 386 | +(UITapGestureRecognizer *) InitTapGestureRecognizerInView:(UIView *)InView NumberOfTapsRequired:(NSUInteger)TapsRequired NumberOfTouchesRequired:(NSUInteger)TouchesRequired Target:(id)Target Actions:(SEL)Action { 387 | 388 | UITapGestureRecognizer *Tap = [[UITapGestureRecognizer alloc] initWithTarget:Target action:Action]; 389 | 390 | Tap.numberOfTapsRequired = TapsRequired; 391 | Tap.numberOfTouchesRequired = TouchesRequired; 392 | 393 | Tap.delegate = Target; 394 | 395 | [InView addGestureRecognizer:Tap]; 396 | 397 | 398 | return Tap; 399 | 400 | } 401 | 402 | 403 | 404 | +(BOOL) isDataPath:(NSString *)Path { 405 | 406 | BOOL isData = NO; 407 | 408 | 409 | BOOL Documents = [CMManager FileExistsAtPath:[NSString stringWithFormat:@"%@Documents",Path]]; 410 | BOOL Library = [CMManager FileExistsAtPath:[NSString stringWithFormat:@"%@Library",Path]]; 411 | 412 | 413 | if (Documents && Library) 414 | isData = YES; 415 | 416 | 417 | return isData; 418 | 419 | } 420 | 421 | +(void) AnimatedDismissView:(UIView *_Nullable)View StartAnimationFrom:(CATransitionSubtype _Nullable)StartAnimationFrom Duration:(float)Duration handler:(void(^_Nullable)(void))handler { 422 | 423 | CATransition *animation = [CATransition animation]; 424 | animation.type = kCATransitionPush; 425 | animation.subtype = StartAnimationFrom; 426 | animation.duration = Duration; 427 | [View.layer addAnimation:animation forKey:nil]; 428 | 429 | View.hidden = YES; 430 | 431 | 432 | [CMManager ActivateTheFollowingCodeAfter:Duration handler:^{ 433 | 434 | [View removeFromSuperview]; 435 | handler(); 436 | 437 | 438 | 439 | }]; 440 | 441 | } 442 | 443 | 444 | UIWindow *WindowSeconds; 445 | UIWindow *Window; 446 | UIView *NView; 447 | +(UIWindow *) InitWindowWithFrame:(CGRect)Frame { 448 | 449 | 450 | Window = [[UIWindow alloc] initWithFrame:Frame]; 451 | WindowSeconds = Window; 452 | 453 | NView = [[UIView alloc] init]; 454 | 455 | NView.frame = Frame; 456 | 457 | 458 | [Window makeKeyAndVisible]; 459 | [Window addSubview:NView]; 460 | 461 | 462 | return Window; 463 | } 464 | 465 | +(void) Start_Main_Thread_Dispatch:(void(^_Nullable)(void))StartDispatch { 466 | 467 | dispatch_async(dispatch_get_main_queue(), ^{ 468 | 469 | StartDispatch(); 470 | }); 471 | 472 | } 473 | 474 | +(UIViewController *) NewViewControllerInView:(UIView *)InView { 475 | 476 | UIViewController *ViewController = [[UIViewController alloc] init]; 477 | 478 | ViewController.view = InView; 479 | 480 | return ViewController; 481 | } 482 | 483 | +(UIView *) InitNewViewInView:(UIView *)InView Frame:(CGRect)Frame { 484 | 485 | UIView *View = [[UIView alloc] initWithFrame:Frame]; 486 | 487 | [InView addSubview:View]; 488 | 489 | return View; 490 | } 491 | 492 | +(AVPlayer *) PlayVideoWithoutCotrollersInView:(UIView *)InView Frame:(CGRect)Frame CornerRadius:(float)CornerRadius VideoPath:(NSString *)VideoPath addObserver:(UIViewController *)Observer Action:(SEL)Action handler:(void(^_Nullable)(id _Nullable PrintThisNote))handler { 493 | 494 | 495 | NSURL *VideoPathURL = [NSURL fileURLWithPath:VideoPath]; 496 | Player = [AVPlayer playerWithURL:VideoPathURL]; 497 | Player.actionAtItemEnd = AVPlayerActionAtItemEndNone; 498 | 499 | AVPlayerLayer *VideoLayer = [AVPlayerLayer playerLayerWithPlayer:Player]; 500 | VideoLayer.frame = Frame; 501 | VideoLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 502 | 503 | [[NSNotificationCenter defaultCenter] addObserver:Observer selector:Action name:AVPlayerItemDidPlayToEndTimeNotification object:[Player currentItem]]; 504 | 505 | [InView.layer addSublayer:VideoLayer]; 506 | 507 | [Player play]; 508 | 509 | VideoLayer.cornerRadius = 20; 510 | VideoLayer.masksToBounds = YES; 511 | 512 | NSString *Note = @"Create New View && Display this player on it && Add \n\n- (void)VideoDidFinish:(NSNotification *)notification {\n\n[ViewName removeFromSuperview];\n\n[NSNotificationCenter.defaultCenter removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:notification.object];\n\n }"; 513 | 514 | handler(Note); 515 | 516 | return Player; 517 | } 518 | 519 | 520 | 521 | 522 | +(UIToolbar *) AddButtonOnKeyboardWithStyle:(UIBarButtonSystemItem)Style ShowOnTextField:(UITextField *)ShowOnTextField Target:(id)Target Action:(SEL)Action { 523 | 524 | UIToolbar* Keyboard = [[UIToolbar alloc] init]; 525 | 526 | [Keyboard sizeToFit]; 527 | 528 | UIBarButtonItem *Item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:Style target:Target action:Action]; 529 | 530 | 531 | 532 | Keyboard.items = @[Item]; 533 | 534 | ShowOnTextField.inputAccessoryView = Keyboard; 535 | 536 | return Keyboard; 537 | } 538 | 539 | 540 | 541 | 542 | +(NSString *) SelfBundle { 543 | 544 | return NSBundle.mainBundle.bundleIdentifier; 545 | } 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | // --------------------------------------------------------------------------------------------------------------------------------------------- 554 | +(CGRect) AboveTabBar { 555 | 556 | float FinalResult = 0; 557 | float UpDown = 0; 558 | if ([CMManager isIPadScreen_Small]) { 559 | 560 | //NSLog(@"iPad Small Screen Detected"); 561 | FinalResult = SCREEN_HEIGHT/1.1 - 15; 562 | UpDown = 38; 563 | 564 | } else if ([CMManager isIPadScreen_12_9_inch]) { 565 | 566 | //NSLog(@"iPad 12_9_inch Screen Detected"); 567 | FinalResult = SCREEN_HEIGHT/1.1 + 16; 568 | UpDown = 38; 569 | 570 | } else if ([CMManager isIPhone_XS_MAX_XR_Screen]) { 571 | 572 | //NSLog(@"isIPhone_XS_MAX_XR_Screen"); 573 | FinalResult = SCREEN_HEIGHT/1.1 - 26; 574 | UpDown = 38; 575 | 576 | } else if ([CMManager isIPhone_X_XS_Screen]) { 577 | 578 | //NSLog(@"isIPhone_X_XS_Screen"); 579 | FinalResult = SCREEN_HEIGHT/1.1 - 31; 580 | UpDown = 35; 581 | 582 | } else if ([CMManager isIPhone_7p_8p_Screen]) { 583 | 584 | //NSLog(@"isIPhone_7p_8p_Screen"); 585 | FinalResult = SCREEN_HEIGHT/1.1 - 15; 586 | UpDown = 20; 587 | 588 | } else if ([CMManager isIPhone_7_8_Screen]) { 589 | 590 | //NSLog(@"isIPhone_7_8_Screen"); 591 | FinalResult = SCREEN_HEIGHT/1.1 - 20; 592 | UpDown = 20; 593 | 594 | } else if ([CMManager isIPhone5Screen]) { 595 | 596 | //NSLog(@"isIPhone5Screen"); 597 | FinalResult = SCREEN_HEIGHT/1.1 - 20; 598 | UpDown = 20; 599 | } 600 | 601 | 602 | 603 | return CGRectMake(0, UpDown, SCREEN_WIDTH, FinalResult); 604 | } 605 | 606 | 607 | AVAudioPlayer *AudioPL; 608 | +(void) PlayAudioFromURL:(NSString *_Nullable)URL { 609 | 610 | NSURL *url = [NSURL URLWithString:URL]; 611 | 612 | NSData *data = [NSData dataWithContentsOfURL:url]; 613 | 614 | AudioPL = [[AVAudioPlayer alloc] initWithData:data error:nil]; 615 | 616 | [AudioPL play]; 617 | 618 | } 619 | 620 | 621 | 622 | AVAudioPlayer *Audioplayer; 623 | +(void) PlayAudioAtPath:(NSString *_Nullable)Path { 624 | 625 | NSURL *SoundPath = [NSURL fileURLWithPath:Path]; 626 | 627 | Audioplayer = [[AVAudioPlayer alloc] initWithContentsOfURL:SoundPath error:nil]; 628 | 629 | [Audioplayer play]; 630 | 631 | } 632 | 633 | +(UIActivityViewController *_Nullable) ShareItemAtPath:(NSString *_Nullable)Path InViewController:(UIViewController *_Nullable)InViewController { 634 | 635 | // To save photo or video to CameraRoll - YOU MUST ADD "NSPhotoLibraryAddUsageDescription" Key to your Info.plist as string 636 | 637 | NSMutableArray *Items = [NSMutableArray new]; 638 | 639 | [Items addObject:[NSURL fileURLWithPath:Path isDirectory:NO]]; 640 | 641 | 642 | UIActivityViewController *Activity = [[UIActivityViewController alloc] initWithActivityItems:Items applicationActivities:nil]; 643 | 644 | [InViewController presentViewController:Activity animated:YES completion:^{ 645 | 646 | 647 | }]; 648 | 649 | return Activity; 650 | } 651 | 652 | 653 | 654 | 655 | +(AVPlayer *) PlayVideoAtPath:(NSURL *_Nullable)Path InViewController:(id _Nullable)ViewController { 656 | 657 | 658 | AVPlayer *Player = [AVPlayer playerWithURL:Path]; 659 | 660 | AVPlayerViewController *PLViewController = [AVPlayerViewController new]; 661 | 662 | [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; 663 | [[AVAudioSession sharedInstance] setActive:YES error:nil]; 664 | 665 | PLViewController.player = Player; 666 | 667 | PLViewController.allowsPictureInPicturePlayback = YES; 668 | 669 | PLViewController.showsPlaybackControls = YES; 670 | 671 | PLViewController.player.allowsExternalPlayback = YES; 672 | 673 | Player.allowsExternalPlayback = YES; 674 | 675 | 676 | [Player play]; 677 | 678 | 679 | 680 | [ViewController presentViewController:PLViewController animated:YES completion:nil]; 681 | 682 | 683 | return Player; 684 | } 685 | 686 | 687 | +(void) RenameItemAtPath:(NSString *_Nullable)Path NewName:(NSString *_Nullable)NewName { 688 | 689 | [[NSFileManager defaultManager] moveItemAtPath:Path toPath:[NSString stringWithFormat:@"%@/%@",[Path stringByDeletingLastPathComponent],NewName] error:nil]; 690 | 691 | 692 | } 693 | 694 | 695 | +(void) InitTextFieldAlertInKeyWindowWithTitle:(NSString *_Nullable)Title Message:(NSString *_Nullable)Message Buttons:(NSArray *_Nullable)Buttons CancelButtonTitle:(NSString *_Nullable)CancelButtonTitle handler:(void(^_Nullable)(NSString * _Nullable ButtonTitle, NSString * _Nullable Text))handler { 696 | 697 | 698 | 699 | 700 | 701 | UIAlertController *alert = [UIAlertController alertControllerWithTitle:Title message:Message preferredStyle:UIAlertControllerStyleAlert]; 702 | 703 | [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { 704 | 705 | 706 | textField.keyboardType = UIKeyboardTypeDefault; 707 | textField.clearButtonMode = UITextFieldViewModeWhileEditing; 708 | [textField resignFirstResponder]; 709 | 710 | 711 | }]; 712 | 713 | for (NSString *EachButton in Buttons) { 714 | 715 | NSArray *fields = alert.textFields; 716 | UITextField *getText = [fields firstObject]; 717 | 718 | UIAlertAction *action = [UIAlertAction actionWithTitle:EachButton style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 719 | 720 | handler(action.title,getText.text); 721 | 722 | 723 | }]; 724 | 725 | 726 | [alert addAction:action]; 727 | 728 | } 729 | 730 | 731 | 732 | if (!(CancelButtonTitle == NULL)) { 733 | 734 | UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:CancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { 735 | 736 | 737 | }]; 738 | 739 | 740 | [alert addAction:cancelAction]; 741 | 742 | } 743 | 744 | 745 | [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alert animated:true completion:nil]; 746 | 747 | 748 | } 749 | 750 | +(void) StartDispatch:(void(^_Nullable)(void))StartDispatch { 751 | 752 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 753 | 754 | StartDispatch(); 755 | 756 | }); 757 | 758 | 759 | } 760 | 761 | 762 | +(void) InitAlertInKeyWindowWithTitle:(NSString *_Nullable)Title Message:(NSString *_Nullable)Message Buttons:(NSArray *_Nullable)Buttons CancelButtonTitle:(NSString *_Nullable)CancelButtonTitle AlertStyle:(UIAlertControllerStyle)AlertStyle handler:(void(^_Nullable)(NSString * _Nullable ButtonTitle))handler { 763 | 764 | 765 | UIAlertController *alert = [UIAlertController alertControllerWithTitle:Title message:Message preferredStyle:AlertStyle]; 766 | 767 | for (NSString *EachButton in Buttons) { 768 | 769 | UIAlertAction *action = [UIAlertAction actionWithTitle:EachButton style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 770 | 771 | handler(action.title); 772 | 773 | 774 | }]; 775 | 776 | 777 | [alert addAction:action]; 778 | } 779 | 780 | 781 | if (!(CancelButtonTitle == NULL)) { 782 | 783 | UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:CancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { 784 | 785 | 786 | 787 | }]; 788 | 789 | //CancelColor 790 | [cancelAction setValue:UIColor.redColor forKey:@"titleTextColor"]; 791 | [alert addAction:cancelAction]; 792 | 793 | } 794 | 795 | 796 | [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alert animated:true completion:nil]; 797 | 798 | 799 | } 800 | 801 | 802 | 803 | +(NSString *_Nullable) ShortenURL:(NSString *_Nullable)URL { 804 | 805 | NSString *StartShorting = [NSString stringWithFormat:@"https://crazy90.com/ShortenURLs/Add.php?url=%@",URL]; 806 | 807 | NSString *Result = [NSString stringWithContentsOfURL:[NSURL URLWithString:StartShorting] encoding:NSUTF8StringEncoding error:nil]; 808 | 809 | 810 | return Result; 811 | 812 | } 813 | 814 | 815 | 816 | +(UIMenuController *_Nullable) InitMenuItemWithTitle:(NSString *_Nullable)Title InView:(UIView *_Nullable)InView Action:(SEL)Action { 817 | 818 | 819 | UIMenuItem *NewItem = [[UIMenuItem alloc] initWithTitle:Title action:Action]; 820 | 821 | 822 | UIMenuController *MenuController = [UIMenuController sharedMenuController]; 823 | 824 | MenuController.menuItems = [NSArray arrayWithObjects: NewItem, nil]; 825 | 826 | CGRect bounds = InView.bounds; 827 | 828 | [MenuController setTargetRect:bounds inView:InView.superview]; 829 | [MenuController setMenuVisible:YES animated: YES]; 830 | 831 | 832 | return MenuController; 833 | } 834 | 835 | 836 | 837 | 838 | 839 | +(UIWindow *_Nullable) NewWindowWithView:(UIView *_Nullable)View { 840 | 841 | 842 | UIWindow *WindowSeconds; 843 | 844 | UIWindow *Window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 845 | WindowSeconds = Window; 846 | [Window makeKeyAndVisible]; 847 | [Window addSubview:View]; 848 | 849 | return Window; 850 | 851 | } 852 | 853 | 854 | +(void) DismissView:(id _Nullable)View { 855 | 856 | 857 | [View removeFromSuperview]; 858 | [View setHidden:YES]; 859 | 860 | } 861 | 862 | 863 | 864 | 865 | +(UIPasteboard *_Nullable) CopyToClipboard:(id _Nullable)Copy { 866 | 867 | UIPasteboard *Pasteboard = [UIPasteboard generalPasteboard]; 868 | Pasteboard.string = Copy; 869 | 870 | return Pasteboard; 871 | } 872 | 873 | +(NSString *_Nullable) PasteFromClipboard { 874 | 875 | NSString *Pasted; 876 | 877 | UIPasteboard *Pasteboard = [UIPasteboard generalPasteboard]; 878 | Pasted = Pasteboard.string; 879 | 880 | return Pasted; 881 | 882 | } 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | +(void) AnimatedDismissView:(UIView *_Nullable)View Duration:(float)Duration Y:(float)DirectionY X:(float)DirectionX handler:(void(^_Nullable)(void))handler { 891 | 892 | 893 | [UIView animateWithDuration:Duration animations:^{ 894 | 895 | View.frame = CGRectOffset(View.bounds, DirectionX, DirectionY); 896 | 897 | }]; 898 | 899 | 900 | [CMManager ActivateTheFollowingCodeAfter:Duration handler:^{ 901 | 902 | handler(); 903 | 904 | }]; 905 | 906 | 907 | } 908 | 909 | +(void) StartDispatch:(void(^_Nullable)(void))StartDispatch EndDispath:(void(^_Nullable)(void))EndDispath { 910 | 911 | 912 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 913 | 914 | StartDispatch(); 915 | 916 | 917 | dispatch_async(dispatch_get_main_queue(), ^{ 918 | 919 | 920 | EndDispath(); 921 | 922 | }); 923 | 924 | }); 925 | 926 | 927 | } 928 | 929 | +(void) SendGETtoPHP:(NSString *_Nullable)SendGETtoPHP handler:(void(^_Nullable)(NSString *Res))handler { 930 | 931 | 932 | NSString *url = SendGETtoPHP; 933 | 934 | NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]]; 935 | [req setHTTPMethod:@"GET"]; 936 | 937 | [[[NSURLSession sharedSession] dataTaskWithRequest:req completionHandler:^(NSData * _Nullable _data, NSURLResponse * _Nullable _response, NSError * _Nullable _error) { 938 | 939 | if (_data) 940 | handler([[NSString alloc] initWithData:_data encoding:NSUTF8StringEncoding]); 941 | 942 | }] 943 | 944 | resume]; 945 | 946 | } 947 | 948 | 949 | +(void) ActivateTheFollowingCodeAfter:(float)Sleep handler:(void(^_Nullable)(void))handler { 950 | 951 | 952 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 953 | 954 | [NSThread sleepForTimeInterval:Sleep]; 955 | 956 | 957 | dispatch_async(dispatch_get_main_queue(), ^{ 958 | 959 | 960 | handler(); 961 | 962 | }); 963 | 964 | }); 965 | 966 | 967 | } 968 | 969 | 970 | 971 | +(void) ResizeLayoutView:(UIView *_Nullable)View InView:(UIView *_Nullable)InView AnchorDirection:(id _Nullable)AnchorDirection Constant:(float)Constant { 972 | 973 | NSString *Formatter = [NSString stringWithFormat:@"%@",AnchorDirection]; 974 | 975 | View.translatesAutoresizingMaskIntoConstraints = NO; 976 | 977 | id AnchorDirection2; 978 | if ([Formatter containsString:@"leading"]) { 979 | AnchorDirection = View.leadingAnchor; 980 | AnchorDirection2 = InView.leadingAnchor; 981 | 982 | } 983 | if ([Formatter containsString:@"top"]) { 984 | AnchorDirection = View.topAnchor; 985 | AnchorDirection2 = InView.topAnchor; 986 | 987 | } 988 | if ([Formatter containsString:@"trailing"]) { 989 | AnchorDirection = View.trailingAnchor; 990 | AnchorDirection2 = InView.trailingAnchor; 991 | 992 | } 993 | if ([Formatter containsString:@"bottom"]) { 994 | AnchorDirection = View.bottomAnchor; 995 | AnchorDirection2 = InView.bottomAnchor; 996 | 997 | } 998 | if ([Formatter containsString:@"centerY"]) { 999 | AnchorDirection = View.centerYAnchor; 1000 | AnchorDirection2 = InView.centerYAnchor; 1001 | 1002 | } 1003 | if ([Formatter containsString:@"centerX"]) { 1004 | AnchorDirection = View.centerXAnchor; 1005 | AnchorDirection2 = InView.centerXAnchor; 1006 | 1007 | } 1008 | 1009 | [AnchorDirection constraintEqualToAnchor:AnchorDirection2 constant:Constant].active = YES; 1010 | 1011 | } 1012 | 1013 | 1014 | 1015 | +(void) ResizeLayoutView:(UIView *_Nullable)View InView:(UIView *_Nullable)InView LeftAnchor:(id _Nullable)LeftAnchor LeftAnchorConstant:(float)LeftAnchorConstant RightAnchor:(id _Nullable)RightAnchor RightAnchorConstant:(float)RightAnchorConstant TopAnchor:(id _Nullable)TopAnchor TopAnchorConstant:(float)TopAnchorConstant BottomAnchor:(id _Nullable)BottomAnchor BottomAnchorConstant:(float)BottomAnchorConstant { 1016 | 1017 | 1018 | View.translatesAutoresizingMaskIntoConstraints = NO; 1019 | 1020 | 1021 | id LeftAnchor2; 1022 | id RightAnchor2; 1023 | id TopAnchor2; 1024 | id BottomAnchor2; 1025 | 1026 | 1027 | LeftAnchor = View.leadingAnchor; 1028 | LeftAnchor2 = InView.leadingAnchor; 1029 | 1030 | 1031 | RightAnchor = View.trailingAnchor; 1032 | RightAnchor2 = InView.trailingAnchor; 1033 | 1034 | 1035 | TopAnchor = View.topAnchor; 1036 | TopAnchor2 = InView.topAnchor; 1037 | 1038 | 1039 | BottomAnchor = View.bottomAnchor; 1040 | BottomAnchor2 = InView.bottomAnchor; 1041 | 1042 | 1043 | [LeftAnchor constraintEqualToAnchor:LeftAnchor2 constant:LeftAnchorConstant].active = YES; 1044 | [RightAnchor constraintEqualToAnchor:RightAnchor2 constant:RightAnchorConstant].active = YES; 1045 | [TopAnchor constraintEqualToAnchor:TopAnchor2 constant:TopAnchorConstant].active = YES; 1046 | [BottomAnchor constraintEqualToAnchor:BottomAnchor2 constant:BottomAnchorConstant].active = YES; 1047 | 1048 | 1049 | } 1050 | 1051 | 1052 | 1053 | +(UIImage *)RoundedImage:(UIImage *) image radius:(float)radius { 1054 | 1055 | CALayer *imageLayer = [CALayer layer]; 1056 | imageLayer.frame = CGRectMake(0, 0, image.size.width, image.size.height); 1057 | imageLayer.contents = (id) image.CGImage; 1058 | 1059 | imageLayer.masksToBounds = YES; 1060 | imageLayer.cornerRadius = radius; 1061 | 1062 | UIGraphicsBeginImageContextWithOptions(image.size, NO, 0); 1063 | [imageLayer renderInContext:UIGraphicsGetCurrentContext()]; 1064 | UIImage *roundedImage = UIGraphicsGetImageFromCurrentImageContext(); 1065 | UIGraphicsEndImageContext(); 1066 | 1067 | return roundedImage; 1068 | 1069 | } 1070 | 1071 | 1072 | 1073 | +(UITextField *_Nullable) InitTextFieldWithFrame:(CGRect)Frame TextColor:(UIColor *_Nullable)TextColor BackgroundColor:(UIColor *_Nullable)BackgroundColor InView:(UIView *_Nullable)InView { 1074 | 1075 | UITextField *TextField = [[UITextField alloc] initWithFrame:Frame]; 1076 | 1077 | TextField.textColor = TextColor; 1078 | TextField.textAlignment = NSTextAlignmentCenter; // NSTextAlignmentRight // NSTextAlignmentLeft 1079 | TextField.backgroundColor = BackgroundColor; 1080 | 1081 | [InView addSubview:TextField]; 1082 | 1083 | return TextField; 1084 | } 1085 | 1086 | 1087 | 1088 | +(CGRect) AboveTabBarDownNavigationController { 1089 | 1090 | // FinalResult : more + more it gets Down 1091 | // ScreeResult : more - more it gets up 1092 | 1093 | 1094 | float FinalResult = 0; 1095 | float ScreeResult = 0; 1096 | 1097 | 1098 | if ([CMManager isIPadScreen_Small]) { 1099 | 1100 | //NSLog(@"iPad Small Screen Detected"); 1101 | FinalResult = SCREEN_HEIGHT/1.2 + 52; 1102 | ScreeResult = SCREEN_HEIGHT/11 - 23; 1103 | 1104 | } else if ([CMManager isIPadScreen_12_9_inch]) { 1105 | 1106 | //NSLog(@"iPad 12_9_inch Screen Detected"); 1107 | FinalResult = SCREEN_HEIGHT/1.2 + 83; 1108 | ScreeResult = SCREEN_HEIGHT/13 - 31; 1109 | 1110 | } else if ([CMManager isIPhone_XS_MAX_XR_Screen]) { 1111 | 1112 | //NSLog(@"isIPhone_XS_MAX_XR_Screen"); 1113 | FinalResult = SCREEN_HEIGHT/1.2 - 5; 1114 | ScreeResult = SCREEN_HEIGHT/12 + 10; 1115 | 1116 | } else if ([CMManager isIPhone_X_XS_Screen]) { 1117 | 1118 | //NSLog(@"isIPhone_X_XS_Screen"); 1119 | FinalResult = SCREEN_HEIGHT/1.2 - 21; 1120 | ScreeResult = SCREEN_HEIGHT/11 + 14; 1121 | 1122 | } else if ([CMManager isIPhone_7p_8p_Screen]) { 1123 | 1124 | //NSLog(@"isIPhone_7p_8p_Screen"); 1125 | FinalResult = SCREEN_HEIGHT/1.2 + 10; 1126 | ScreeResult = SCREEN_HEIGHT/10 - 10; 1127 | 1128 | } else if ([CMManager isIPhone_7_8_Screen]) { 1129 | 1130 | //NSLog(@"isIPhone_7_8_Screen"); 1131 | FinalResult = SCREEN_HEIGHT/1.2 - 1; 1132 | ScreeResult = SCREEN_HEIGHT/10 - 3; 1133 | 1134 | } else if ([CMManager isIPhone5Screen]) { 1135 | 1136 | //NSLog(@"isIPhone5Screen"); 1137 | FinalResult = SCREEN_HEIGHT/1.2 - 18; 1138 | ScreeResult = SCREEN_HEIGHT/10 + 7; 1139 | } 1140 | 1141 | 1142 | 1143 | return CGRectMake(0, ScreeResult, SCREEN_WIDTH, FinalResult); 1144 | } 1145 | 1146 | 1147 | 1148 | 1149 | +(UINavigationController *_Nullable) InitNavigationControllerWithTitle:(NSString *_Nullable)Title TitleColor:(UIColor *_Nullable)TitleColor RightButtonTitle:(NSString *_Nullable)RightButtonTitle RightButtonAction:(SEL _Nullable )RightButtonAction LeftButtonImage:(NSString *_Nullable)LeftButtonImage LeftButtonAction:(SEL _Nullable)LeftButtonAction ButtonsColor:(UIColor *_Nullable)ButtonsColor BackgroundColor:(UIColor *_Nullable)BackgroundColor Target:(id _Nullable)Target InView:(UIView *_Nullable)InView { 1150 | 1151 | 1152 | UIViewController *ViewCont = [UIViewController new]; 1153 | 1154 | UINavigationController *NavigationCont = [[UINavigationController alloc] initWithRootViewController:ViewCont]; 1155 | 1156 | ViewCont.title = Title; 1157 | 1158 | [NavigationCont.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : TitleColor}]; // TitleColor 1159 | [NavigationCont.navigationBar setTintColor:ButtonsColor]; // Buttons Color 1160 | [NavigationCont.navigationBar setBarTintColor:BackgroundColor]; // Background Color 1161 | 1162 | 1163 | 1164 | ViewCont.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:RightButtonTitle style:UIBarButtonItemStyleDone target:Target action:RightButtonAction]; 1165 | 1166 | if (LeftButtonImage != nil) 1167 | ViewCont.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:LeftButtonImage] style:UIBarButtonItemStylePlain target:Target action:LeftButtonAction]; 1168 | 1169 | 1170 | 1171 | [InView addSubview:NavigationCont.view]; 1172 | 1173 | return NavigationCont; 1174 | } 1175 | 1176 | 1177 | +(UINavigationController *_Nullable) InitNavigationControllerWithTitle:(NSString *_Nullable)Title TitleColor:(UIColor *_Nullable)TitleColor RightButtonTitle:(NSString *_Nullable)RightButtonTitle RightButtonAction:(SEL _Nullable )RightButtonAction LeftButtonImage:(NSString *_Nullable)LeftButtonImage LeftButtonAction:(SEL _Nullable)LeftButtonAction EditButtonTitle:(NSString *_Nullable)EditButtonTitle EditButtonAction:(SEL)EditButtonAction ButtonsColor:(UIColor *_Nullable)ButtonsColor BackgroundColor:(UIColor *_Nullable)BackgroundColor Target:(id _Nullable)Target InView:(UIView *_Nullable)InView { 1178 | 1179 | 1180 | UIViewController *ViewCont = [UIViewController new]; 1181 | 1182 | UINavigationController *NavigationCont = [[UINavigationController alloc] initWithRootViewController:ViewCont]; 1183 | 1184 | ViewCont.title = Title; 1185 | 1186 | [NavigationCont.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:TitleColor}]; // TitleColor 1187 | [NavigationCont.navigationBar setTintColor:ButtonsColor]; // Buttons Color 1188 | [NavigationCont.navigationBar setBarTintColor:BackgroundColor]; // Background Color 1189 | 1190 | 1191 | 1192 | ViewCont.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:RightButtonTitle style:UIBarButtonItemStyleDone target:Target action:RightButtonAction]; 1193 | 1194 | UIBarButtonItem *Item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:LeftButtonImage] style:UIBarButtonItemStylePlain target:Target action:LeftButtonAction]; 1195 | UIBarButtonItem *Item1 = [[UIBarButtonItem alloc] initWithTitle:EditButtonTitle style:UIBarButtonItemStyleDone target:Target action:EditButtonAction]; 1196 | 1197 | ViewCont.navigationItem.leftBarButtonItems = @[Item,Item1]; 1198 | 1199 | NavigationCont.toolbarItems = @[]; 1200 | 1201 | [InView addSubview:NavigationCont.view]; 1202 | 1203 | return NavigationCont; 1204 | } 1205 | 1206 | 1207 | +(CGRect) InMiddleOfView:(UIView *_Nullable)View { 1208 | 1209 | 1210 | return CGRectMake(View.frame.size.width*0.2*1.2, View.frame.size.height*0.3, View.frame.size.width*0.5, View.frame.size.height*0.2*1.2); 1211 | } 1212 | 1213 | +(CGRect) AboveTabBarDownNavigationBar { 1214 | 1215 | float FinalResult = 0; 1216 | float ScreeResult = 0; 1217 | if ([CMManager isIPadScreen_Small]) { 1218 | 1219 | //NSLog(@"iPad Small Screen Detected"); 1220 | FinalResult = SCREEN_HEIGHT/1.2 + 30; 1221 | ScreeResult = SCREEN_HEIGHT/11 - 3; 1222 | 1223 | } else if ([CMManager isIPadScreen_12_9_inch]) { 1224 | 1225 | //NSLog(@"iPad 12_9_inch Screen Detected"); 1226 | FinalResult = SCREEN_HEIGHT/1.2 + 54; 1227 | ScreeResult = SCREEN_HEIGHT/13 - 2; 1228 | 1229 | } else if ([CMManager isIPhone_XS_MAX_XR_Screen]) { 1230 | 1231 | //NSLog(@"isIPhone_XS_MAX_XR_Screen"); 1232 | FinalResult = SCREEN_HEIGHT/1.2 + 5; 1233 | ScreeResult = SCREEN_HEIGHT/12; 1234 | 1235 | } else if ([CMManager isIPhone_X_XS_Screen]) { 1236 | 1237 | //NSLog(@"isIPhone_X_XS_Screen"); 1238 | FinalResult = SCREEN_HEIGHT/1.2 - 8; 1239 | ScreeResult = SCREEN_HEIGHT/11; 1240 | 1241 | } else if ([CMManager isIPhone_7p_8p_Screen]) { 1242 | 1243 | //NSLog(@"isIPhone_7p_8p_Screen"); 1244 | FinalResult = SCREEN_HEIGHT/1.2 + 1; 1245 | ScreeResult = SCREEN_HEIGHT/10 - 1; 1246 | 1247 | } else if ([CMManager isIPhone_7_8_Screen]) { 1248 | 1249 | //NSLog(@"isIPhone_7_8_Screen"); 1250 | FinalResult = SCREEN_HEIGHT/1.2 - 7; 1251 | ScreeResult = SCREEN_HEIGHT/10 + 3; 1252 | 1253 | } else if ([CMManager isIPhone5Screen]) { 1254 | 1255 | //NSLog(@"isIPhone5Screen"); 1256 | FinalResult = SCREEN_HEIGHT/1.2 - 12; 1257 | ScreeResult = SCREEN_HEIGHT/10; 1258 | } 1259 | 1260 | 1261 | 1262 | return CGRectMake(0, ScreeResult, SCREEN_WIDTH, FinalResult); 1263 | } 1264 | 1265 | 1266 | 1267 | 1268 | +(void) InitTextFieldAlertWithTitle:(NSString *_Nullable)Title Message:(NSString *_Nullable)Message Buttons:(NSArray *_Nullable)Buttons CancelButtonTitle:(NSString *_Nullable)CancelButtonTitle handler:(void(^_Nullable)(NSString * _Nullable ButtonTitle, NSString * _Nullable Text, UITextField * _Nullable TextField))handler { 1269 | 1270 | 1271 | UIAlertController *alert = [UIAlertController alertControllerWithTitle:Title message:Message preferredStyle:UIAlertControllerStyleAlert]; 1272 | 1273 | [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { 1274 | 1275 | 1276 | // textField.keyboardType = UIKeyboardTypeDefault; 1277 | textField.clearButtonMode = UITextFieldViewModeWhileEditing; 1278 | [textField resignFirstResponder]; 1279 | 1280 | handler(nil,nil,textField); 1281 | 1282 | }]; 1283 | 1284 | for (NSString *EachButton in Buttons) { 1285 | 1286 | NSArray *fields = alert.textFields; 1287 | UITextField *getText = [fields firstObject]; 1288 | 1289 | UIAlertAction *action = [UIAlertAction actionWithTitle:EachButton style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 1290 | 1291 | handler(action.title,getText.text,nil); 1292 | 1293 | }]; 1294 | 1295 | 1296 | [alert addAction:action]; 1297 | 1298 | } 1299 | 1300 | 1301 | 1302 | if (!(CancelButtonTitle == NULL)) { 1303 | 1304 | UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:CancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { 1305 | 1306 | 1307 | }]; 1308 | 1309 | 1310 | [alert addAction:cancelAction]; 1311 | 1312 | } 1313 | 1314 | 1315 | [topMostController() presentViewController:alert animated:true completion:nil]; 1316 | 1317 | 1318 | } 1319 | 1320 | 1321 | 1322 | 1323 | +(void) InitTextFieldAlertWithTitle:(NSString *_Nullable)Title TitleColor:(UIColor *_Nullable)TitleColor Message:(NSString *_Nullable)Message MessageColor:(UIColor *_Nullable)MessageColor Buttons:(NSArray *_Nullable)Buttons ButtonsColor:(UIColor *_Nullable)ButtonsColor ButtonsImage:(UIImage *_Nullable)ButtonsImage BackgroundColor:(UIColor *_Nullable)BackgroundColor TextFieldBGColor:(UIColor *_Nullable)TextFieldBGColor TextFieldTextColor:(UIColor *_Nullable)TextFieldTextColor CancelButtonTitle:(NSString *_Nullable)CancelButtonTitle handler:(void(^_Nullable)(NSString * _Nullable ButtonTitle, NSString * _Nullable Text))handler { 1324 | 1325 | 1326 | UIWindow *Win = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 1327 | 1328 | 1329 | 1330 | UIViewController *controller = [[UIViewController alloc] init]; 1331 | 1332 | 1333 | 1334 | Win.rootViewController = [UIViewController new]; 1335 | 1336 | Win.windowLevel = UIWindowLevelAlert + 1; 1337 | 1338 | Win.rootViewController = controller; 1339 | 1340 | 1341 | UIAlertController *alert = [UIAlertController alertControllerWithTitle:Title message:Message preferredStyle:UIAlertControllerStyleAlert]; 1342 | 1343 | [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { 1344 | 1345 | 1346 | textField.keyboardType = UIKeyboardTypeDefault; 1347 | textField.clearButtonMode = UITextFieldViewModeWhileEditing; 1348 | [textField resignFirstResponder]; 1349 | textField.backgroundColor = TextFieldBGColor; 1350 | textField.textColor = TextFieldTextColor; 1351 | textField.borderStyle = UITextBorderStyleRoundedRect; 1352 | textField.keyboardAppearance = UIKeyboardAppearanceDark; 1353 | 1354 | 1355 | }]; 1356 | 1357 | for (NSString *EachButton in Buttons) { 1358 | 1359 | NSArray *fields = alert.textFields; 1360 | UITextField *getText = [fields firstObject]; 1361 | 1362 | UIAlertAction *action = [UIAlertAction actionWithTitle:EachButton style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 1363 | 1364 | handler(action.title,getText.text); 1365 | 1366 | [Win setHidden:YES]; 1367 | 1368 | }]; 1369 | 1370 | 1371 | [alert addAction:action]; 1372 | 1373 | [action setValue:ButtonsColor forKey:@"titleTextColor"]; 1374 | 1375 | [action setValue:[ButtonsImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"]; 1376 | 1377 | } 1378 | 1379 | 1380 | // BackgroundColor 1381 | 1382 | UIView *firstSubview = alert.view.subviews.firstObject; 1383 | 1384 | UIView *alertContentView = firstSubview.subviews.firstObject; 1385 | 1386 | for (UIView *subSubView in alertContentView.subviews) { 1387 | 1388 | subSubView.backgroundColor = BackgroundColor; 1389 | 1390 | } 1391 | 1392 | 1393 | 1394 | 1395 | // TitleColor 1396 | 1397 | UIColor *color = TitleColor; 1398 | 1399 | NSString *string = Title; 1400 | 1401 | NSDictionary *attrs = @{ NSForegroundColorAttributeName:color}; 1402 | 1403 | NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:string attributes:attrs]; 1404 | 1405 | [alert setValue:attrStr forKey:@"attributedTitle"]; 1406 | 1407 | 1408 | 1409 | 1410 | 1411 | // MessageColor 1412 | 1413 | UIColor *color1 = MessageColor; 1414 | 1415 | NSString *string1 = Message; 1416 | 1417 | NSDictionary *attrs1 = @{ NSForegroundColorAttributeName:color1}; 1418 | 1419 | NSAttributedString *attrStr1 = [[NSAttributedString alloc] initWithString:string1 attributes:attrs1]; 1420 | 1421 | [alert setValue:attrStr1 forKey:@"attributedMessage"]; 1422 | 1423 | 1424 | 1425 | if (!(CancelButtonTitle == NULL)) { 1426 | 1427 | UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:CancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { 1428 | 1429 | 1430 | [Win setHidden:YES]; 1431 | }]; 1432 | 1433 | 1434 | [alert addAction:cancelAction]; 1435 | 1436 | //CancelColor 1437 | [cancelAction setValue:UIColor.redColor forKey:@"titleTextColor"]; 1438 | 1439 | 1440 | } 1441 | 1442 | 1443 | [Win makeKeyAndVisible]; 1444 | 1445 | [controller presentViewController:alert animated:true completion:nil]; 1446 | 1447 | 1448 | 1449 | } 1450 | 1451 | 1452 | 1453 | 1454 | 1455 | 1456 | 1457 | 1458 | 1459 | 1460 | +(UITextView *_Nullable) InitTextViewWithFrame:(CGRect)Frame BackgroundColor:(UIColor *_Nullable)BGColor TextColor:(UIColor *_Nullable)TextColor InView:(UIView *_Nullable)InView { 1461 | 1462 | UITextView *TextV = [[UITextView alloc] initWithFrame:Frame]; 1463 | 1464 | TextV.backgroundColor = BGColor; 1465 | TextV.textColor = TextColor; 1466 | 1467 | [InView addSubview:TextV]; 1468 | 1469 | return TextV; 1470 | } 1471 | 1472 | +(UITextView *_Nullable) InitTextViewWithBGColor:(UIColor *_Nullable)BGColor TextColor:(UIColor *_Nullable)TextColor LeftRight:(float)LeftRight UpDown:(float)UpDown Width:(float)Width Height:(float)Height InView:(UIView *_Nullable)InView { 1473 | 1474 | CGRect LFrame = CGRectMake(InView.frame.size.width*LeftRight, InView.frame.size.height*UpDown, InView.frame.size.width*Width, InView.frame.size.height*Height); 1475 | 1476 | UITextView *TextV = [[UITextView alloc] initWithFrame:LFrame]; 1477 | 1478 | TextV.backgroundColor = BGColor; 1479 | TextV.textColor = TextColor; 1480 | 1481 | [InView addSubview:TextV]; 1482 | 1483 | return TextV; 1484 | 1485 | } 1486 | 1487 | 1488 | 1489 | +(BOOL) isDirectory:(NSString *_Nullable)Path { 1490 | 1491 | BOOL Directory = NO; 1492 | 1493 | if ([[NSFileManager defaultManager] fileExistsAtPath:Path isDirectory:&Directory] && Directory) 1494 | Directory = YES; 1495 | 1496 | return Directory; 1497 | } 1498 | 1499 | +(UISegmentedControl *) InitSegamentWithSections:(NSArray *)Sections Target:(id)Target Action:(SEL)Action InView:(UIView *)View { 1500 | 1501 | 1502 | UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:Sections]; 1503 | 1504 | [segmentedControl addTarget:Target action:Action forControlEvents: UIControlEventValueChanged]; 1505 | segmentedControl.selectedSegmentIndex = 0; 1506 | [View addSubview:segmentedControl]; 1507 | 1508 | return segmentedControl; 1509 | } 1510 | 1511 | +(UIScrollView *_Nullable) InitScrollViewWithBGColor:(UIColor *_Nullable)BGColor LeftRight:(float)LeftRight UpDown:(float)UpDown Width:(float)Width Height:(float)Height Delegate:(id)Delegate InView:(UIView *_Nullable)InView { 1512 | 1513 | 1514 | CGRect LFrame = CGRectMake(InView.frame.size.width*LeftRight, InView.frame.size.height*UpDown, InView.frame.size.width*Width, InView.frame.size.height*Height); 1515 | 1516 | UIScrollView *ScrollView = [[UIScrollView alloc] initWithFrame:LFrame]; 1517 | 1518 | ScrollView.delegate = Delegate; 1519 | ScrollView.backgroundColor = BGColor; 1520 | ScrollView.showsVerticalScrollIndicator = YES; 1521 | ScrollView.scrollEnabled = YES; 1522 | ScrollView.userInteractionEnabled = YES; 1523 | [InView addSubview:ScrollView]; 1524 | 1525 | return ScrollView; 1526 | } 1527 | 1528 | +(UIScrollView *_Nullable) InitScrollViewWithFrame:(CGRect)Frame BGColor:(UIColor *_Nullable)BGColor Delegate:(id)Delegate InView:(UIView *_Nullable)InView { 1529 | 1530 | 1531 | UIScrollView *ScrollView = [[UIScrollView alloc] initWithFrame:Frame]; 1532 | 1533 | ScrollView.delegate = Delegate; 1534 | ScrollView.backgroundColor = BGColor; 1535 | ScrollView.showsVerticalScrollIndicator = YES; 1536 | ScrollView.scrollEnabled = YES; 1537 | ScrollView.userInteractionEnabled = YES; 1538 | [InView addSubview:ScrollView]; 1539 | 1540 | return ScrollView; 1541 | 1542 | } 1543 | 1544 | +(void)ViewToBeAnimated:(UIView *_Nullable)views delegate:(id _Nullable)delegate Duration:(float)Duration StartAnimationFrom:(CATransitionSubtype _Nullable)StartAnimationFrom { 1545 | 1546 | CATransition *transition = nil; 1547 | transition = [CATransition animation]; 1548 | transition.duration = Duration; 1549 | transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 1550 | transition.type = kCATransitionPush; 1551 | transition.subtype = StartAnimationFrom; 1552 | transition.delegate = delegate; 1553 | [views.layer addAnimation:transition forKey:nil]; 1554 | 1555 | } 1556 | 1557 | 1558 | +(UIImage *) imageFromView:(UIView *)view { 1559 | 1560 | UIGraphicsBeginImageContext(view.frame.size); 1561 | CGContextRef currentContext = UIGraphicsGetCurrentContext(); 1562 | CGContextTranslateCTM(currentContext, 0, view.frame.size.height); 1563 | 1564 | CGContextScaleCTM(currentContext, 1.0, -1.0); 1565 | [[view layer] renderInContext:currentContext]; 1566 | UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); 1567 | UIGraphicsEndImageContext(); 1568 | 1569 | return screenshot; 1570 | } 1571 | 1572 | +(UIVisualEffectView *) BlurView:(UIView *_Nullable)View { 1573 | 1574 | 1575 | UIVisualEffect *blurEffect; 1576 | blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; 1577 | 1578 | UIVisualEffectView *visualEffectView; 1579 | visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; 1580 | 1581 | visualEffectView.frame = View.bounds; 1582 | visualEffectView.layer.cornerRadius = View.layer.cornerRadius; 1583 | visualEffectView.layer.masksToBounds = YES; 1584 | 1585 | 1586 | [View addSubview:visualEffectView]; 1587 | 1588 | [visualEffectView setTranslatesAutoresizingMaskIntoConstraints:false]; 1589 | [visualEffectView.heightAnchor constraintEqualToAnchor:View.heightAnchor].active = YES; 1590 | [visualEffectView.widthAnchor constraintEqualToAnchor:View.widthAnchor].active = YES; 1591 | 1592 | return visualEffectView; 1593 | } 1594 | 1595 | 1596 | 1597 | +(NSString *_Nonnull) CheckDeviceType { 1598 | size_t size = 100; 1599 | char *hw_machine = malloc(size); 1600 | int name[] = {CTL_HW,HW_MACHINE}; 1601 | sysctl(name, 2, hw_machine, &size, NULL, 0); 1602 | NSString *hardware = [NSString stringWithUTF8String:hw_machine]; 1603 | free(hw_machine); 1604 | 1605 | return hardware; 1606 | } 1607 | 1608 | 1609 | 1610 | +(BOOL) isIPhone_XS_MAX_XR_Screen { 1611 | 1612 | BOOL isIPhone_XS_MAX_XR_Screen; 1613 | 1614 | if (SCREEN_HEIGHT == 896) 1615 | isIPhone_XS_MAX_XR_Screen = YES; 1616 | else 1617 | isIPhone_XS_MAX_XR_Screen = NO; 1618 | 1619 | 1620 | return isIPhone_XS_MAX_XR_Screen; 1621 | } 1622 | 1623 | 1624 | +(BOOL) isIPhone_X_XS_Screen { 1625 | 1626 | BOOL isIPhone_X_XS_Screen; 1627 | 1628 | if (SCREEN_HEIGHT == 812) 1629 | isIPhone_X_XS_Screen = YES; 1630 | else 1631 | isIPhone_X_XS_Screen = NO; 1632 | 1633 | 1634 | return isIPhone_X_XS_Screen; 1635 | } 1636 | 1637 | 1638 | 1639 | +(BOOL) isIPadScreen_12_9_inch { 1640 | 1641 | BOOL isIPadScreen_12_9_inch; 1642 | 1643 | if (SCREEN_HEIGHT > 1300) 1644 | isIPadScreen_12_9_inch = YES; 1645 | else 1646 | isIPadScreen_12_9_inch = NO; 1647 | 1648 | 1649 | return isIPadScreen_12_9_inch; 1650 | } 1651 | 1652 | 1653 | 1654 | 1655 | +(BOOL) isIPadScreen_Small { 1656 | 1657 | BOOL isIPadScreen_Small; 1658 | 1659 | if (SCREEN_HEIGHT > 900 && SCREEN_HEIGHT < 1300) 1660 | isIPadScreen_Small = YES; 1661 | else 1662 | isIPadScreen_Small = NO; 1663 | 1664 | 1665 | return isIPadScreen_Small; 1666 | } 1667 | 1668 | 1669 | +(BOOL) isIPhone_7p_8p_Screen { 1670 | 1671 | BOOL isIPhone_7p_8p_Screen; 1672 | 1673 | if (SCREEN_HEIGHT == 736) 1674 | isIPhone_7p_8p_Screen = YES; 1675 | else 1676 | isIPhone_7p_8p_Screen = NO; 1677 | 1678 | 1679 | return isIPhone_7p_8p_Screen; 1680 | 1681 | } 1682 | 1683 | 1684 | +(BOOL) isIPhone_7_8_Screen { 1685 | 1686 | BOOL isIPhone_7_8_Screen; 1687 | 1688 | if (SCREEN_HEIGHT == 667) 1689 | isIPhone_7_8_Screen = YES; 1690 | else 1691 | isIPhone_7_8_Screen = NO; 1692 | 1693 | 1694 | return isIPhone_7_8_Screen; 1695 | 1696 | } 1697 | 1698 | 1699 | 1700 | +(BOOL) isIPhone5Screen { 1701 | 1702 | BOOL isIPhone5Screen; 1703 | 1704 | if (SCREEN_HEIGHT <= 568) 1705 | 1706 | isIPhone5Screen = YES; 1707 | else 1708 | isIPhone5Screen = NO; 1709 | 1710 | 1711 | return isIPhone5Screen; 1712 | 1713 | } 1714 | 1715 | 1716 | +(UISwitch *_Nonnull) InitSwitchInsideViewWithAction:(SEL _Nullable )Action LeftRight:(float)LeftRight UpDown:(float)UpDown Width:(float)Width Height:(float)Height InView:(UIView *_Nullable)InView Target:(id _Nullable )Target { 1717 | 1718 | CGRect LFrame = CGRectMake(InView.frame.size.width*LeftRight, InView.frame.size.height*UpDown, InView.frame.size.width*Width, InView.frame.size.height*Height); 1719 | 1720 | UISwitch *Switch = [[UISwitch alloc] initWithFrame:LFrame]; 1721 | 1722 | [Switch addTarget:Target action:Action forControlEvents:UIControlEventTouchUpInside]; 1723 | 1724 | Switch.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin); 1725 | 1726 | [InView addSubview:Switch]; 1727 | 1728 | 1729 | return Switch; 1730 | 1731 | } 1732 | 1733 | 1734 | 1735 | 1736 | +(UISwitch *_Nonnull) InitSwitchAction:(SEL _Nullable )Action Frame:(CGRect)Frame InView:(UIView *_Nullable)InView Target:(id _Nullable )Target { 1737 | 1738 | 1739 | UISwitch *Switch = [[UISwitch alloc] initWithFrame:Frame]; 1740 | 1741 | [Switch addTarget:Target action:Action forControlEvents:UIControlEventTouchUpInside]; 1742 | 1743 | Switch.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin); 1744 | 1745 | [InView addSubview:Switch]; 1746 | 1747 | 1748 | return Switch; 1749 | 1750 | } 1751 | 1752 | 1753 | +(UIImage *_Nullable) BlureImage:(UIImage *_Nullable)image BlureLevel:(float)BlureLevel InView:(UIView *_Nullable)InView { 1754 | 1755 | UIView *ff = [[UIView alloc] initWithFrame:InView.bounds]; 1756 | 1757 | UIImage *sourceImage = image; 1758 | UIImageView *imageView = [[UIImageView alloc] initWithFrame:InView.bounds]; 1759 | 1760 | CIContext *context = [CIContext contextWithOptions:nil]; 1761 | CIImage *inputImage = [CIImage imageWithCGImage:sourceImage.CGImage]; 1762 | 1763 | CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"]; 1764 | [filter setValue:inputImage forKey:kCIInputImageKey]; 1765 | [filter setValue:[NSNumber numberWithFloat:BlureLevel] forKey:@"inputRadius"]; 1766 | CIImage *result = [filter valueForKey:kCIOutputImageKey]; 1767 | 1768 | 1769 | CGImageRef cgImage = [context createCGImage:result fromRect:[inputImage extent]]; 1770 | 1771 | UIImage *retVal = [UIImage imageWithCGImage:cgImage]; 1772 | 1773 | if (cgImage) { 1774 | CGImageRelease(cgImage); 1775 | } 1776 | 1777 | imageView.image = retVal; 1778 | [ff addSubview:imageView]; 1779 | 1780 | 1781 | UIGraphicsBeginImageContextWithOptions(ff.bounds.size, ff.opaque, 0.0); 1782 | [ff.layer renderInContext:UIGraphicsGetCurrentContext()]; 1783 | 1784 | UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); 1785 | 1786 | UIGraphicsEndImageContext(); 1787 | 1788 | return img; 1789 | 1790 | } 1791 | 1792 | +(NSArray *) InitButtonLabelWithName:(NSString *)Name InView:(UIView *)View Target:(id)Target Action:(SEL)Action { 1793 | 1794 | UILabel *Label = [[UILabel alloc] init]; 1795 | 1796 | Label.text = Name; 1797 | 1798 | [View addSubview:Label]; 1799 | 1800 | 1801 | UIButton *Button = [UIButton buttonWithType:UIButtonTypeCustom]; 1802 | 1803 | [Button setTitle:@"" forState:UIControlStateNormal]; 1804 | 1805 | [Button addTarget:Target action:Action forControlEvents:UIControlEventTouchUpInside]; 1806 | 1807 | [View addSubview:Button]; 1808 | 1809 | [Button setTranslatesAutoresizingMaskIntoConstraints:NO]; 1810 | 1811 | [NSLayoutConstraint activateConstraints:@[ 1812 | 1813 | [Button.topAnchor constraintEqualToAnchor:Label.topAnchor constant:0], 1814 | [Button.leadingAnchor constraintEqualToAnchor:Label.leadingAnchor constant:0], 1815 | [Button.trailingAnchor constraintEqualToAnchor:Label.trailingAnchor constant:0], 1816 | [Button.bottomAnchor constraintEqualToAnchor:Label.bottomAnchor constant:0], 1817 | 1818 | ]]; 1819 | 1820 | NSArray *Values = @[Button,Label]; 1821 | 1822 | return Values; 1823 | 1824 | } 1825 | 1826 | +(NSArray *_Nullable) InitLabelImage:(UIImage *_Nullable)image InView:(UIView *_Nullable)View LabelName:(NSString *)Name { 1827 | 1828 | 1829 | UIImageView *ImageView = [[UIImageView alloc] init]; 1830 | 1831 | ImageView.image = image; 1832 | 1833 | ImageView.layer.masksToBounds = YES; 1834 | 1835 | [View addSubview:ImageView]; 1836 | 1837 | 1838 | UILabel *Label = [[UILabel alloc] init]; 1839 | 1840 | Label.text = Name; 1841 | Label.textAlignment = NSTextAlignmentCenter; 1842 | Label.textColor = UIColor.whiteColor; 1843 | 1844 | [ImageView addSubview:Label]; 1845 | 1846 | [Label setTranslatesAutoresizingMaskIntoConstraints:NO]; 1847 | 1848 | [NSLayoutConstraint activateConstraints:@[ 1849 | 1850 | [Label.topAnchor constraintEqualToAnchor:ImageView.topAnchor constant:15], 1851 | [Label.leadingAnchor constraintEqualToAnchor:ImageView.leadingAnchor constant:15], 1852 | [Label.trailingAnchor constraintEqualToAnchor:ImageView.trailingAnchor constant:-16], 1853 | [Label.bottomAnchor constraintEqualToAnchor:ImageView.bottomAnchor constant:-27], 1854 | 1855 | ]]; 1856 | 1857 | NSArray *Values = @[Label,ImageView]; 1858 | 1859 | return Values; 1860 | 1861 | } 1862 | 1863 | +(NSArray *_Nullable) InitButtonImage:(UIImage *_Nullable)image InView:(UIView *_Nullable)View Target:(id)Target Action:(SEL)Action { 1864 | 1865 | 1866 | UIImageView *ImageView = [[UIImageView alloc] init]; 1867 | 1868 | ImageView.image = image; 1869 | 1870 | ImageView.layer.masksToBounds = YES; 1871 | 1872 | [View addSubview:ImageView]; 1873 | 1874 | 1875 | UIButton *Button = [UIButton buttonWithType:UIButtonTypeCustom]; 1876 | 1877 | [Button setTitle:@"" forState:UIControlStateNormal]; 1878 | 1879 | [Button addTarget:Target action:Action forControlEvents:UIControlEventTouchUpInside]; 1880 | 1881 | 1882 | [View addSubview:Button]; 1883 | 1884 | [Button setTranslatesAutoresizingMaskIntoConstraints:NO]; 1885 | 1886 | [NSLayoutConstraint activateConstraints:@[ 1887 | 1888 | [Button.topAnchor constraintEqualToAnchor:ImageView.topAnchor constant:0], 1889 | [Button.leadingAnchor constraintEqualToAnchor:ImageView.leadingAnchor constant:0], 1890 | [Button.trailingAnchor constraintEqualToAnchor:ImageView.trailingAnchor constant:0], 1891 | [Button.bottomAnchor constraintEqualToAnchor:ImageView.bottomAnchor constant:0], 1892 | 1893 | ]]; 1894 | 1895 | NSArray *Values = @[Button,ImageView]; 1896 | 1897 | return Values; 1898 | 1899 | } 1900 | 1901 | 1902 | 1903 | 1904 | +(UIImageView *_Nullable) InitImage:(UIImage *_Nullable)image Frame:(CGRect)Frame InView:(UIView *_Nullable)InView { 1905 | 1906 | 1907 | UIImageView *ImageView = [[UIImageView alloc] initWithFrame:Frame]; 1908 | 1909 | ImageView.image = image; 1910 | 1911 | ImageView.layer.masksToBounds = YES; 1912 | 1913 | [InView addSubview:ImageView]; 1914 | 1915 | return ImageView; 1916 | } 1917 | 1918 | +(UIImageView *_Nullable) InitImage:(UIImage *_Nullable)image LeftRight:(float)LeftRight UpDown:(float)UpDown Width:(float)Width Height:(float)Height InView:(UIView *_Nullable)InView { 1919 | 1920 | CGRect ImFrame = CGRectMake(InView.frame.size.width*LeftRight, InView.frame.size.height*UpDown, InView.frame.size.width*Width, InView.frame.size.height*Height); 1921 | 1922 | UIImageView *ImageView = [[UIImageView alloc] initWithFrame:ImFrame]; 1923 | 1924 | ImageView.image = image; 1925 | 1926 | ImageView.layer.masksToBounds = YES; 1927 | 1928 | [InView addSubview:ImageView]; 1929 | 1930 | return ImageView; 1931 | } 1932 | 1933 | +(void) InitAlertWithTitle:(NSString *_Nullable)Title TitleColor:(UIColor *_Nullable)TitleColor TitleImage:(UIImage *)TitleImage TitleImageFrame:(CGRect)TitleImageFrame Message:(NSString *_Nullable)Message MessageColor:(UIColor *_Nullable)MessageColor Buttons:(NSArray *_Nullable)Buttons CancelButtonTitle:(NSString *_Nullable)CancelButtonTitle ButtonsColor:(UIColor *_Nullable)ButtonsColor ButtonsImage:(UIImage *_Nullable)ButtonsImage BackgroundColor:(UIColor *_Nullable)BackgroundColor AlertStyle:(UIAlertControllerStyle)AlertStyle handler:(void(^_Nullable)(NSString * _Nullable ButtonTitle))handler { 1934 | 1935 | UIWindow *Win = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 1936 | 1937 | UIViewController *controller = [[UIViewController alloc] init]; 1938 | 1939 | Win.rootViewController = [UIViewController new]; 1940 | 1941 | Win.windowLevel = UIWindowLevelAlert + 1; 1942 | 1943 | Win.rootViewController = controller; 1944 | 1945 | 1946 | UIAlertController *alert = [UIAlertController alertControllerWithTitle:Title message:Message preferredStyle:AlertStyle]; 1947 | 1948 | 1949 | for (NSString *EachButton in Buttons) { 1950 | 1951 | UIAlertAction *action = [UIAlertAction actionWithTitle:EachButton style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 1952 | 1953 | handler(action.title); 1954 | 1955 | [Win setHidden:YES]; 1956 | 1957 | }]; 1958 | 1959 | 1960 | [alert addAction:action]; 1961 | 1962 | [action setValue:ButtonsColor forKey:@"titleTextColor"]; 1963 | 1964 | [action setValue:[ButtonsImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"]; 1965 | 1966 | } 1967 | 1968 | 1969 | 1970 | if (!(CancelButtonTitle == NULL)) { 1971 | 1972 | UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:CancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { 1973 | 1974 | 1975 | [Win setHidden:YES]; 1976 | 1977 | }]; 1978 | 1979 | //CancelColor 1980 | [cancelAction setValue:UIColor.redColor forKey:@"titleTextColor"]; 1981 | [alert addAction:cancelAction]; 1982 | 1983 | } 1984 | 1985 | // BackgroundColor 1986 | UIView *firstSubview = alert.view.subviews.firstObject; 1987 | UIView *alertContentView = firstSubview.subviews.firstObject; 1988 | for (UIView *subSubView in alertContentView.subviews) { 1989 | subSubView.backgroundColor = BackgroundColor; 1990 | } 1991 | 1992 | 1993 | // TitleColor 1994 | UIColor *color = TitleColor; 1995 | NSString *string = Title; 1996 | NSDictionary *attrs = @{ NSForegroundColorAttributeName:color}; 1997 | NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:string attributes:attrs]; 1998 | 1999 | [alert setValue:attrStr forKey:@"attributedTitle"]; 2000 | 2001 | 2002 | // MessageColor 2003 | UIColor *color1 = MessageColor; 2004 | NSString *string1 = Message; 2005 | NSDictionary *attrs1 = @{ NSForegroundColorAttributeName:color1}; 2006 | NSAttributedString *attrStr1 = [[NSAttributedString alloc] initWithString:string1 attributes:attrs1]; 2007 | 2008 | [alert setValue:attrStr1 forKey:@"attributedMessage"]; 2009 | 2010 | 2011 | 2012 | [CMManager InitImage:TitleImage Frame:TitleImageFrame InView:alert.view]; 2013 | 2014 | 2015 | [Win makeKeyAndVisible]; 2016 | [controller presentViewController:alert animated:true completion:nil]; 2017 | 2018 | 2019 | 2020 | } 2021 | 2022 | 2023 | +(UIView *_Nullable) InitViewWithFrame:(CGRect)Frame InView:(UIView *_Nullable)InView { 2024 | 2025 | UIView *View = [[UIView alloc] initWithFrame:Frame]; 2026 | 2027 | // View.backgroundColor = BGColor; 2028 | 2029 | // View.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin); 2030 | 2031 | 2032 | [InView addSubview:View]; 2033 | 2034 | return View; 2035 | } 2036 | 2037 | 2038 | //+(void) InitAlertWithTitle:(NSString *_Nullable)Title Message:(NSString *_Nullable)Message Buttons:(NSArray *_Nullable)Buttons CancelButtonTitle:(NSString *_Nullable)CancelButtonTitle AlertStyle:(UIAlertControllerStyle)AlertStyle handler:(void(^_Nullable)(NSString * _Nullable ButtonTitle))handler { 2039 | // 2040 | // 2041 | // 2042 | // UIAlertController *alert = [UIAlertController alertControllerWithTitle:Title message:Message preferredStyle:AlertStyle]; 2043 | // 2044 | // for (NSString *EachButton in Buttons) { 2045 | // 2046 | // UIAlertAction *action = [UIAlertAction actionWithTitle:EachButton style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 2047 | // 2048 | // handler(action.title); 2049 | // 2050 | // 2051 | // }]; 2052 | // 2053 | // 2054 | // [alert addAction:action]; 2055 | // } 2056 | // 2057 | // 2058 | // if (!(CancelButtonTitle == NULL)) { 2059 | // 2060 | // UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:CancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { 2061 | // 2062 | // handler(action.title); 2063 | // 2064 | // }]; 2065 | // 2066 | // //CancelColor 2067 | // [cancelAction setValue:UIColor.redColor forKey:@"titleTextColor"]; 2068 | // [alert addAction:cancelAction]; 2069 | // 2070 | // } 2071 | // 2072 | // [topMostController() presentViewController:alert animated:true completion:nil]; 2073 | // 2074 | // 2075 | //} 2076 | 2077 | +(void) RemoveALLItemsInDirectory:(NSString *)Dir { 2078 | 2079 | NSArray *fileList = [CMManager ContentOfDir:Dir]; 2080 | for(NSInteger i = 0; i < [fileList count]; ++i) { 2081 | 2082 | NSString *fp = [fileList objectAtIndex:i]; 2083 | NSString *remPath = [Dir stringByAppendingPathComponent:fp]; 2084 | 2085 | [CMManager RemoveItemAtPath:remPath]; 2086 | 2087 | } 2088 | } 2089 | 2090 | +(UIButton *) InitButtonInsideViewWithName:(NSString *)BuName LeftRight:(float)LeftRight UpDown:(float)UpDown Width:(float)Width Height:(float)Height InView:(UIView *)InView Target:(id)Target Action:(SEL)Action { 2091 | 2092 | 2093 | CGRect LFrame = CGRectMake(InView.frame.size.width*LeftRight, InView.frame.size.height*UpDown, InView.frame.size.width*Width, InView.frame.size.height*Height); 2094 | 2095 | 2096 | UIButton *Button = [UIButton buttonWithType:UIButtonTypeCustom]; 2097 | 2098 | Button.frame = LFrame; 2099 | 2100 | Button.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin); 2101 | 2102 | [Button setTitle:BuName forState:UIControlStateNormal]; 2103 | 2104 | 2105 | [Button addTarget:Target action:Action forControlEvents:UIControlEventTouchUpInside]; 2106 | 2107 | 2108 | 2109 | [InView addSubview:Button]; 2110 | 2111 | 2112 | return Button; 2113 | 2114 | } 2115 | 2116 | 2117 | +(UIButton *) InitButtonWithName:(NSString *)BuName Frame:(CGRect)frame InView:(UIView *)View Target:(id)Target Action:(SEL)Action { 2118 | 2119 | 2120 | UIButton *Button = [UIButton buttonWithType:UIButtonTypeCustom]; 2121 | 2122 | Button.frame = frame; 2123 | 2124 | [Button setTitle:BuName forState:UIControlStateNormal]; 2125 | 2126 | 2127 | [Button addTarget:Target action:Action forControlEvents:UIControlEventTouchUpInside]; 2128 | 2129 | 2130 | 2131 | [View addSubview:Button]; 2132 | 2133 | 2134 | return Button; 2135 | 2136 | } 2137 | 2138 | 2139 | 2140 | 2141 | +(void) Target:(id)Target Perfomrer:(SEL)Perf { 2142 | 2143 | 2144 | [Target performSelector:Perf]; 2145 | 2146 | 2147 | } 2148 | 2149 | +(UIButton *) InitButtonWithName:(NSString *)BuName LeftRight:(float)LeftRight UpDown:(float)UpDown Width:(float)Width Height:(float)Height InView:(UIView *)View Target:(id)Target Action:(SEL)Action { 2150 | 2151 | float LeftNRight = [UIScreen mainScreen].bounds.size.width; 2152 | float UpAndDown = [UIScreen mainScreen].bounds.size.height; 2153 | 2154 | float width = [UIScreen mainScreen].bounds.size.width; 2155 | float height = [UIScreen mainScreen].bounds.size.height; 2156 | 2157 | CGRect BFrame = CGRectMake(LeftNRight*LeftRight, UpAndDown*UpDown, width*Width, height*Height); 2158 | 2159 | UIButton *Button = [UIButton buttonWithType:UIButtonTypeCustom]; 2160 | 2161 | Button.frame = BFrame; 2162 | 2163 | Button.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin); 2164 | 2165 | [Button setTitle:BuName forState:UIControlStateNormal]; 2166 | 2167 | 2168 | [Button addTarget:Target action:Action forControlEvents:UIControlEventTouchUpInside]; 2169 | 2170 | 2171 | 2172 | [View addSubview:Button]; 2173 | 2174 | 2175 | return Button; 2176 | 2177 | } 2178 | 2179 | 2180 | 2181 | +(UIView *_Nullable) InitViewWithBGColor:(UIColor *_Nullable)BGColor Frame:(CGRect)Frame Blur:(BOOL)Blur BackgroundImage:(UIImage *_Nullable)BackgroundImage InView:(UIView *_Nullable)InView { 2182 | 2183 | 2184 | 2185 | 2186 | CGRect BFrame = Frame; //CGRectMake(SCREEN_WIDTH/LeftRight, SCREEN_HEIGHT/UpDown, SCREEN_WIDTH/Width, SCREEN_HEIGHT/Height); 2187 | 2188 | 2189 | UIView *View = [[UIView alloc] initWithFrame:BFrame]; 2190 | 2191 | 2192 | if (Blur) { 2193 | 2194 | UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; 2195 | UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; 2196 | 2197 | blurEffectView.frame = View.bounds; 2198 | 2199 | blurEffectView.layer.cornerRadius = 20; 2200 | blurEffectView.layer.masksToBounds = YES; 2201 | 2202 | 2203 | [View addSubview:blurEffectView]; 2204 | 2205 | } 2206 | 2207 | View.backgroundColor = BGColor; 2208 | 2209 | View.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin); 2210 | 2211 | if (BackgroundImage != nil) { 2212 | 2213 | UIImageView *IMView = [[UIImageView alloc] initWithImage:BackgroundImage]; 2214 | 2215 | IMView.layer.masksToBounds = YES; 2216 | 2217 | IMView.layer.cornerRadius = 20; 2218 | 2219 | View.layer.contents = CFBridgingRelease((IMView.image.CGImage)); 2220 | 2221 | } 2222 | 2223 | [InView addSubview:View]; 2224 | 2225 | return View; 2226 | 2227 | } 2228 | 2229 | 2230 | +(UIView *_Nullable) InitViewWithBGColor:(UIColor *_Nullable)BGColor Frame:(CGRect)Frame BackgroundImage:(UIImage *_Nullable)BackgroundImage InView:(UIView *_Nullable)InView { 2231 | 2232 | UIView *View = [[UIView alloc] initWithFrame:Frame]; 2233 | 2234 | View.backgroundColor = BGColor; 2235 | 2236 | View.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin); 2237 | 2238 | if (BackgroundImage != nil) { 2239 | 2240 | UIImage *Image = BackgroundImage; 2241 | 2242 | View.layer.contents = (__bridge id _Nullable)(Image.CGImage); 2243 | 2244 | } 2245 | 2246 | [InView addSubview:View]; 2247 | 2248 | return View; 2249 | } 2250 | 2251 | 2252 | +(UILabel *) InitLabelWithName:(NSString *)Name TextAlignment:(NSTextAlignment)TextAlignment LeftRight:(float)LeftRight UpDown:(float)UpDown Width:(float)Width Height:(float)Height InView:(UIView *)InView { 2253 | 2254 | float LeftNRight = [UIScreen mainScreen].bounds.size.width; 2255 | float UpAndDown = [UIScreen mainScreen].bounds.size.height; 2256 | 2257 | float width = [UIScreen mainScreen].bounds.size.width; 2258 | float height = [UIScreen mainScreen].bounds.size.height; 2259 | 2260 | CGRect BFrame = CGRectMake(LeftNRight*LeftRight, UpAndDown*UpDown, width*Width, height*Height); 2261 | 2262 | UILabel *Label = [[UILabel alloc] initWithFrame:BFrame]; 2263 | 2264 | Label.text = Name; 2265 | 2266 | Label.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin); 2267 | 2268 | Label.textAlignment = TextAlignment; 2269 | 2270 | [InView addSubview:Label]; 2271 | 2272 | return Label; 2273 | } 2274 | 2275 | 2276 | +(NSString *)TakeStringFromLeft:(NSString *)TakeStringFromLeft HowMuch:(NSUInteger)HowMuch { 2277 | 2278 | NSUInteger length = TakeStringFromLeft.length; 2279 | NSUInteger cut = length - HowMuch; 2280 | NSString *OldKey = [TakeStringFromLeft substringToIndex:[TakeStringFromLeft length] - cut]; 2281 | 2282 | return OldKey; 2283 | } 2284 | 2285 | +(UILabel *) InitLabelWithName:(NSString *)Name Frame:(CGRect)frame InView:(UIView *)InView { 2286 | 2287 | 2288 | UILabel *Label = [[UILabel alloc] initWithFrame:frame]; 2289 | 2290 | Label.text = Name; 2291 | 2292 | [InView addSubview:Label]; 2293 | 2294 | return Label; 2295 | } 2296 | 2297 | 2298 | 2299 | +(UILabel *) InitLabelInsideViewWithName:(NSString *)Name TextAlignment:(NSTextAlignment)TextAlignment TextColor:(UIColor *)TextColor LeftRight:(float)LeftRight UpDown:(float)UpDown Width:(float)Width Height:(float)Height InView:(UIView *)InView { 2300 | 2301 | 2302 | 2303 | CGRect LFrame = CGRectMake(InView.frame.size.width*LeftRight, InView.frame.size.height*UpDown, InView.frame.size.width*Width, InView.frame.size.height*Height); 2304 | 2305 | UILabel *Label = [[UILabel alloc] initWithFrame:LFrame]; 2306 | 2307 | Label.text = Name; 2308 | 2309 | Label.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin); 2310 | 2311 | Label.textColor = TextColor; 2312 | 2313 | Label.textAlignment = TextAlignment; 2314 | 2315 | [InView addSubview:Label]; 2316 | 2317 | return Label; 2318 | } 2319 | 2320 | 2321 | 2322 | 2323 | 2324 | 2325 | +(NSString *)SizeOfFile:(NSString *)SizeOfFile { 2326 | 2327 | NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:SizeOfFile error:nil]; 2328 | NSInteger fileSize = [[fileAttributes objectForKey:NSFileSize] integerValue]; 2329 | NSString *fileSizeStr = [NSByteCountFormatter stringFromByteCount:fileSize countStyle:NSByteCountFormatterCountStyleFile]; 2330 | return fileSizeStr; 2331 | } 2332 | 2333 | 2334 | +(NSString *) SizeOfFolder:(NSString *)sizeOfFolder { 2335 | 2336 | NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:sizeOfFolder error:nil]; 2337 | NSEnumerator *contentsEnumurator = [contents objectEnumerator]; 2338 | 2339 | NSString *file; 2340 | unsigned long long int folderSize = 0; 2341 | 2342 | while (file = [contentsEnumurator nextObject]) { 2343 | NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[sizeOfFolder stringByAppendingPathComponent:file] error:nil]; 2344 | folderSize += [[fileAttributes objectForKey:NSFileSize] intValue]; 2345 | } 2346 | 2347 | NSString *folderSizeStr = [NSByteCountFormatter stringFromByteCount:folderSize countStyle:NSByteCountFormatterCountStyleFile]; 2348 | return folderSizeStr; 2349 | } 2350 | 2351 | 2352 | 2353 | +(NSArray *) ContentOfDir:(NSString *)ContentOfDir { 2354 | 2355 | 2356 | NSArray *Arr = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:ContentOfDir error:nil]; 2357 | 2358 | [Arr reverseObjectEnumerator]; 2359 | 2360 | 2361 | 2362 | return Arr; 2363 | 2364 | } 2365 | 2366 | 2367 | 2368 | +(BOOL) PlistPath:(NSString *)PlistPath RemoveObjectForKey:(id)RemoveObjectForKey { 2369 | 2370 | static bool Success; 2371 | NSMutableDictionary *MuD = [[NSMutableDictionary alloc] initWithContentsOfFile:PlistPath]; 2372 | [MuD removeObjectForKey:RemoveObjectForKey]; 2373 | Success = [MuD writeToFile:PlistPath atomically:YES]; 2374 | 2375 | return Success; 2376 | } 2377 | 2378 | +(NSString *) RemoveAllNumbersFromString:(NSString *)String { 2379 | 2380 | NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 2381 | NSCharacterSet *notLetters = [[NSCharacterSet characterSetWithCharactersInString:letters] invertedSet]; 2382 | NSString *newString = [[String componentsSeparatedByCharactersInSet:notLetters] componentsJoinedByString:@""]; 2383 | 2384 | return newString; 2385 | } 2386 | 2387 | +(NSString *) RemoveAllLettersFromString:(NSString *)String { 2388 | 2389 | 2390 | NSString *letters = @"1234567890"; 2391 | NSCharacterSet *notLetters = [[NSCharacterSet characterSetWithCharactersInString:letters] invertedSet]; 2392 | NSString *newString = [[String componentsSeparatedByCharactersInSet:notLetters] componentsJoinedByString:@""]; 2393 | 2394 | return newString; 2395 | } 2396 | 2397 | +(NSDictionary *) GetJSONFromURL:(NSString *)URL { 2398 | 2399 | NSString *CallLink = URL; 2400 | NSDictionary *Finder; 2401 | 2402 | 2403 | NSURL *URLs = [NSURL URLWithString:CallLink]; 2404 | NSData *Data = [NSData dataWithContentsOfURL:URLs]; 2405 | 2406 | if (Data.length == 0) { 2407 | 2408 | 2409 | 2410 | } else 2411 | Finder = [NSJSONSerialization JSONObjectWithData:Data options:0 error:nil]; 2412 | 2413 | 2414 | return Finder; 2415 | 2416 | } 2417 | 2418 | 2419 | +(id) BundlePathWithFileOrDir:(NSString *)BundlePathWithFileOrDir { 2420 | 2421 | NSString *path = [[NSBundle mainBundle] bundlePath]; 2422 | NSString *RealP = [path stringByAppendingPathComponent:BundlePathWithFileOrDir]; 2423 | 2424 | return RealP; 2425 | } 2426 | 2427 | 2428 | +(id) DataPathWithFileOrDir:(NSString *)DataPathWithFileOrDir { 2429 | 2430 | NSString *Go = [NSString stringWithFormat:@"%@/%@",NSHomeDirectory(),DataPathWithFileOrDir]; 2431 | 2432 | return Go; 2433 | } 2434 | 2435 | 2436 | +(void) SendGETtoPHP:(NSString *)SendGETtoPHP { 2437 | 2438 | NSString *url = SendGETtoPHP; 2439 | 2440 | NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]]; 2441 | [req setHTTPMethod:@"GET"]; 2442 | 2443 | [[[NSURLSession sharedSession] dataTaskWithRequest:req completionHandler:^(NSData * _Nullable _data, NSURLResponse * _Nullable _response, NSError * _Nullable _error) { 2444 | 2445 | }] 2446 | 2447 | resume]; 2448 | 2449 | } 2450 | 2451 | 2452 | +(BOOL) PlistPath:(NSString *)PlistPath SetValue:(id)SetValue ForKey:(id)ForKey { 2453 | 2454 | static bool Success; 2455 | 2456 | NSMutableDictionary *MutDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:PlistPath]; 2457 | [MutDictionary setValue:SetValue forKey:ForKey]; 2458 | Success = [MutDictionary writeToFile:PlistPath atomically:YES]; 2459 | 2460 | return Success; 2461 | } 2462 | 2463 | 2464 | +(NSString *) PlistPath:(NSString *)PlistPath ObjectForKey:(id)ObjectForKey { 2465 | 2466 | 2467 | NSMutableDictionary *MutDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:PlistPath]; 2468 | NSString *GetValue = [MutDictionary objectForKey:ObjectForKey]; 2469 | 2470 | return GetValue; 2471 | 2472 | } 2473 | 2474 | 2475 | 2476 | 2477 | 2478 | +(id) Generator:(NSUInteger)Num { 2479 | 2480 | NSString *alphabet = @"0123456789"; 2481 | NSMutableString *Generator = [NSMutableString stringWithCapacity:Num]; 2482 | for (NSUInteger i = 0U; i < Num; i++) { 2483 | u_int32_t r = arc4random() % [alphabet length]; 2484 | unichar c = [alphabet characterAtIndex:r]; 2485 | [Generator appendFormat:@"%C", c]; 2486 | 2487 | } 2488 | 2489 | NSString *Crazy = [NSString stringWithFormat:@"%@",Generator]; 2490 | 2491 | return Crazy; 2492 | 2493 | } 2494 | 2495 | 2496 | +(id) GeneratorTwos:(NSUInteger)Num { 2497 | 2498 | NSString *alphabet = @"0246802468"; 2499 | NSMutableString *Generator = [NSMutableString stringWithCapacity:Num]; 2500 | for (NSUInteger i = 0U; i < Num; i++) { 2501 | u_int32_t r = arc4random() % [alphabet length]; 2502 | unichar c = [alphabet characterAtIndex:r]; 2503 | [Generator appendFormat:@"%C", c]; 2504 | 2505 | } 2506 | 2507 | NSString *Crazy = [NSString stringWithFormat:@"%@",Generator]; 2508 | 2509 | return Crazy; 2510 | 2511 | } 2512 | 2513 | 2514 | 2515 | 2516 | 2517 | +(BOOL) CreatePlistAtPath:(NSString *)CreatePlistAtPath NameWithoutExtension:(NSString *)NameWithoutExtension { 2518 | 2519 | 2520 | 2521 | 2522 | NSString *PlistPath = CreatePlistAtPath; 2523 | 2524 | NSString *PlistName = [PlistPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist",NameWithoutExtension]]; 2525 | 2526 | bool Success = [@{} writeToFile:PlistName atomically: YES]; 2527 | 2528 | return Success; 2529 | 2530 | 2531 | } 2532 | 2533 | +(BOOL) FileExistsAtPath:(NSString *)FileExistsAtPath { 2534 | 2535 | NSFileManager *FileManager = [NSFileManager defaultManager]; 2536 | 2537 | bool Success = [FileManager fileExistsAtPath:FileExistsAtPath]; 2538 | 2539 | return Success; 2540 | } 2541 | 2542 | +(BOOL) RemoveItemAtPath:(NSString *)RemoveItemAtPath { 2543 | 2544 | NSFileManager *FileManager = [NSFileManager defaultManager]; 2545 | NSError *error; 2546 | 2547 | bool Success = [FileManager removeItemAtPath:RemoveItemAtPath error:&error]; 2548 | 2549 | return Success; 2550 | } 2551 | 2552 | +(BOOL) CopyItemAtPath:(NSString *)CopyItemAtPath ToPath:(NSString *)ToPath { 2553 | 2554 | NSFileManager *FileManager = [NSFileManager defaultManager]; 2555 | 2556 | 2557 | bool Success = [FileManager copyItemAtPath:CopyItemAtPath toPath:ToPath error:nil]; 2558 | 2559 | return Success; 2560 | 2561 | } 2562 | 2563 | 2564 | +(BOOL) MoveItemAtPath:(NSString *)MoveItemAtPath ToPath:(NSString *)ToPath { 2565 | 2566 | NSFileManager *FileManager = [NSFileManager defaultManager]; 2567 | 2568 | 2569 | bool Success = [FileManager moveItemAtPath:MoveItemAtPath toPath:ToPath error:nil]; 2570 | 2571 | return Success; 2572 | 2573 | } 2574 | 2575 | +(BOOL) CreateDirectoryAtPath:(NSString *)CreateDirectoryAtPath { 2576 | 2577 | NSFileManager *FileManager = [NSFileManager defaultManager]; 2578 | NSError *error; 2579 | 2580 | 2581 | bool Success = [FileManager createDirectoryAtPath:CreateDirectoryAtPath withIntermediateDirectories:YES attributes:nil error:&error]; 2582 | 2583 | return Success; 2584 | 2585 | } 2586 | 2587 | +(BOOL) CreateFileAtPath:(NSString *)CreateFileAtPath { 2588 | 2589 | NSFileManager *FileManager = [NSFileManager defaultManager]; 2590 | 2591 | bool Success = [FileManager createFileAtPath:CreateFileAtPath contents:nil attributes:nil]; 2592 | 2593 | return Success; 2594 | 2595 | } 2596 | 2597 | +(BOOL) DownloadLink:(NSString *)DownloadLink ToPath:(NSString *)ToPath { 2598 | 2599 | NSString *stringURL = DownloadLink; 2600 | NSURL *url = [NSURL URLWithString:stringURL]; 2601 | NSData *urlData = [NSData dataWithContentsOfURL:url]; 2602 | 2603 | static bool Success; 2604 | 2605 | if (urlData) { 2606 | 2607 | NSString *DownName = [DownloadLink lastPathComponent]; 2608 | NSString *Download = [ToPath stringByAppendingPathComponent:DownName]; 2609 | 2610 | NSString *filePath = [NSString stringWithFormat:@"%@",Download]; 2611 | Success = [urlData writeToFile:filePath atomically:YES]; 2612 | 2613 | //NSLog(@"filePath ===== %@",filePath); 2614 | 2615 | } 2616 | 2617 | return Success; 2618 | } 2619 | 2620 | 2621 | +(void) UploadFile:(NSString *)UploadFile PHPLink:(NSString *)PHPLink PHPNameValue:(NSString *)PHPNameValue { 2622 | 2623 | 2624 | 2625 | NSString *LastP = [UploadFile lastPathComponent]; 2626 | 2627 | NSData *Data = [[NSData alloc] initWithContentsOfFile:UploadFile]; 2628 | 2629 | 2630 | 2631 | NSString *urlString = PHPLink; 2632 | 2633 | NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; 2634 | [request setURL:[NSURL URLWithString:urlString]]; 2635 | [request setHTTPMethod:@"POST"]; 2636 | request.timeoutInterval = 60; 2637 | request.HTTPShouldHandleCookies = false; 2638 | 2639 | 2640 | NSString *boundary = @"---------------------------14737809831466499882746641449"; 2641 | NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary]; 2642 | [request addValue:contentType forHTTPHeaderField: @"Content-Type"]; 2643 | 2644 | NSMutableData *body = [NSMutableData data]; 2645 | [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 2646 | [body appendData:[[NSString stringWithString:[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n",PHPNameValue,LastP]] dataUsingEncoding:NSUTF8StringEncoding]]; 2647 | [body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; 2648 | [body appendData:[NSData dataWithData:Data]]; 2649 | [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 2650 | 2651 | [request setHTTPBody:body]; 2652 | 2653 | 2654 | [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable _data, NSURLResponse * _Nullable _response, NSError * _Nullable _error) { 2655 | 2656 | 2657 | 2658 | }] 2659 | 2660 | resume]; 2661 | 2662 | 2663 | 2664 | 2665 | 2666 | } 2667 | 2668 | 2669 | 2670 | 2671 | 2672 | 2673 | @end 2674 | --------------------------------------------------------------------------------