Commit d98e6b3d by zhangyunjie

1.0.0.0

parent 0b15dc7f
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1120"
LastUpgradeVersion = "0720"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
......@@ -14,9 +14,9 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A9661B3F24EA64ED0024EB54"
BuildableName = "OffcnIMSDKiOS.app"
BlueprintName = "OffcnIMSDKiOS"
BlueprintIdentifier = "6003F589195388D20070C39A"
BuildableName = "OffcnIMSDKiOS_Example.app"
BlueprintName = "OffcnIMSDKiOS_Example"
ReferencedContainer = "container:OffcnIMSDKiOS.xcodeproj">
</BuildableReference>
</BuildActionEntry>
......@@ -28,7 +28,28 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6003F5AD195388D20070C39A"
BuildableName = "OffcnIMSDKiOS_Tests.xctest"
BlueprintName = "OffcnIMSDKiOS_Tests"
ReferencedContainer = "container:OffcnIMSDKiOS.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6003F589195388D20070C39A"
BuildableName = "OffcnIMSDKiOS_Example.app"
BlueprintName = "OffcnIMSDKiOS_Example"
ReferencedContainer = "container:OffcnIMSDKiOS.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
......@@ -44,15 +65,17 @@
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A9661B3F24EA64ED0024EB54"
BuildableName = "OffcnIMSDKiOS.app"
BlueprintName = "OffcnIMSDKiOS"
BlueprintIdentifier = "6003F589195388D20070C39A"
BuildableName = "OffcnIMSDKiOS_Example.app"
BlueprintName = "OffcnIMSDKiOS_Example"
ReferencedContainer = "container:OffcnIMSDKiOS.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Debug"
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
......@@ -61,9 +84,9 @@
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A9661B3F24EA64ED0024EB54"
BuildableName = "OffcnIMSDKiOS.app"
BlueprintName = "OffcnIMSDKiOS"
BlueprintIdentifier = "6003F589195388D20070C39A"
BuildableName = "OffcnIMSDKiOS_Example.app"
BlueprintName = "OffcnIMSDKiOS_Example"
ReferencedContainer = "container:OffcnIMSDKiOS.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
......
......@@ -12,7 +12,7 @@
#import "OffcnIMSDKiOS.h"
#import "OffcnIMSocketManager.h"
#import "OffcnIMZYJFMDBHandler.h"
#import "AppDelegate+OffcnIMPush.h"
#import "OffcnIMPushManager.h"
@interface AppDelegate ()
......@@ -40,7 +40,7 @@
//启动SDK
[[OffcnIMSDKiOS defaultService] setupWithIsTest:YES];
//注册推送
[AppDelegate registerOffcnUserNotificationSettingsWithApplication:application options:launchOptions];
[OffcnIMPushManager registerOffcnUserNotificationSettingsWithApplication:application options:launchOptions];
//获取用户相关数据库,该方法在登陆或者第一次启动已登陆下执行
[[OffcnIMZYJFMDBHandler sharedInstance] getUserDB];
......@@ -85,7 +85,7 @@
//解析deviceToken
NSString *str = [AppDelegate hexStringForData:deviceToken];
NSString *str = [OffcnIMPushManager hexStringForData:deviceToken];
[OffcnIMSDKiOS defaultService].deviceToken = str;
NSLog(@"token--- %@",str);
}
......@@ -99,7 +99,7 @@
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSLog(@"接收到远程推送通知Background ---- %@", userInfo);
[AppDelegate didReceiveRemoteNotification:userInfo];
[OffcnIMPushManager didReceiveRemoteNotification:userInfo];
// if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
//
......@@ -111,7 +111,7 @@
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
NSLog(@"接收到远程推送通知 ---- %@", userInfo);
[AppDelegate didReceiveRemoteNotification:userInfo];
[OffcnIMPushManager didReceiveRemoteNotification:userInfo];
//将推送消息以alert形式呈现
// NSString *message = [[userInfo objectForKey:@"aps"]objectForKey:@"alert"];
......
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15510"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
......@@ -12,13 +14,13 @@
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Seh-6S-vx3"/>
<viewControllerLayoutGuide type="bottom" id="BW3-NG-9nf"/>
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
......
......@@ -3,48 +3,50 @@
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSCameraUsageDescription</key>
<string>App需要您的同意,才能访问相机</string>
<key>NSMicrophoneUsageDescription</key>
<string>App需要您的同意,才能访问麦克风</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能访问相册</string>
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSCameraUsageDescription</key>
<string>App需要您的同意,才能访问相机</string>
<key>NSMicrophoneUsageDescription</key>
<string>App需要您的同意,才能访问麦克风</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能访问相册</string>
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UIStatusBarHidden</key>
<true/>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
......
//
// Prefix header
//
// The contents of this file are implicitly included at the beginning of every source file.
//
#import <Availability.h>
#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif
#ifdef __OBJC__
@import UIKit;
@import Foundation;
#endif
//
//
//
// SDLabel.h
// ViewController.h
// OffcnIMSDKiOS
//
// Created by vockey on 2018/8/8.
// Created by vockey on 2018/7/25.
// Copyright © 2018年 中公教育. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface SDLabel : UILabel
#define kOffcnIMSDKiOS_changeEnvironment @"kOffcnIMSDKiOS_changeEnvironment"
@interface ViewController : UIViewController
@property (assign, nonatomic) UIEdgeInsets edgeInsets;
@end
/* Localized versions of Info.plist keys */
//
// main.m
// OffcnIMSDKiOS
//
// Created by zhangyunjie   on 09/15/2020.
// Copyright (c) 2020 zhangyunjie  . All rights reserved.
//
@import UIKit;
#import "AppDelegate.h"
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
use_frameworks!
platform :ios, '8.0'
target 'OffcnIMSDKiOS_Example' do
pod 'OffcnIMSDKiOS', :path => '../'
target 'OffcnIMSDKiOS_Tests' do
inherit! :search_paths
end
end
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
// The contents of this file are implicitly included at the beginning of every test case source file.
#ifdef __OBJC__
#endif
//
// OffcnIMSDKiOSTests.m
// OffcnIMSDKiOSTests
//
// Created by zhangyunjie   on 09/15/2020.
// Copyright (c) 2020 zhangyunjie  . All rights reserved.
//
@import XCTest;
@interface Tests : XCTestCase
@end
@implementation Tests
- (void)setUp
{
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testExample
{
XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__);
}
@end
/* Localized versions of Info.plist keys */
Copyright (c) 2020 zhangyunjie   <zhangyunjie@offcn.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
#
# Be sure to run `pod lib lint OffcnIMSDKiOS.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'OffcnIMSDKiOS'
s.version = '1.0.0.0'
s.summary = 'OffcnIMSDKiOS.'
s.description = <<-DESC
TODO: Add long description of the pod here.
DESC
s.homepage = 'https://gitlab.eoffcn.com/zhangyunjie/OffcnIMSDKiOS.git'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'zhangyunjie' => 'zhangyunjie@offcn.com' }
s.source = { :git => 'https://gitlab.eoffcn.com/zhangyunjie/OffcnIMSDKiOS.git', :tag => s.version.to_s }
s.requires_arc = true
s.ios.deployment_target = '9.0'
s.source_files = 'OffcnIMSDKiOS/Classes/*.h'
s.public_header_files = 'OffcnIMSDKiOS/Classes/*.h'
#vendored_frameworks: 第三方framework
s.vendored_frameworks = ['OffcnIMSDKiOS/Frameworks/oimcore.framework']
#frameworks: 该pod依赖的系统framework
s.frameworks = 'SystemConfiguration', 'CoreTelephony'
s.vendored_libraries = ['OffcnIMSDKiOS/Libraries/libOffcnIMSDKiOS.a']
#libraries: 该pod依赖的系统library
s.libraries = 'c++','sqlite3','xml2','resolv'
# s.resource = 'OffcnIMSDKiOS/Resources/*.bundle'
s.user_target_xcconfig = {'OTHER_LDFLAGS' => '-ObjC'}
#dependency : 该pod依赖的pod
end
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
//
//
//
// AppDelegate+OffcnIMPush.h
// OffcnIMPushManager.h
// OffcnIMSDKiOS
//
// Created by vockey on 2020/9/1.
// Copyright © 2020 offcn. All rights reserved.
//
#import "AppDelegate.h"
#import "OffcnIMModel.h"
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface AppDelegate (OffcnIMPush)
@interface OffcnIMPushManager : NSObject
//注册通知
+(void)registerOffcnUserNotificationSettingsWithApplication:(UIApplication *)application options:(NSDictionary *)launchOptions;
......
//
//
......@@ -33,6 +33,7 @@ typedef void(^OffcnIMReceiveConnectStatus)(OffcnIMConnectStatus status,NSString
@property (nonatomic, copy) NSString *msg_fromId;//发送消息的用户id
@property (nonatomic, copy) NSString *token;//发送消息的用户token
@property (nonatomic, assign) BOOL isManualDisconnect;//是手动断开的连接
@property (nonatomic, assign) OffcnIMConnectStatus IMConnectStatus;//连接状态
......@@ -53,6 +54,9 @@ typedef void(^OffcnIMReceiveConnectStatus)(OffcnIMConnectStatus status,NSString
//断开连接
-(void)disConnectIMServer;
//重新连接
-(void)reconnectionIMServer;
//后台收到消息本地推送
-(void)manualSendLocalNotificationWithModel:(OffcnIMModel *)model;
@end
......
//
++ /dev/null
//
// ConfigrationNetwork.h
// OffcnIMSDKiOS
//
// Created by vockey on 2018/7/25.
// Copyright © 2018年 中公教育. All rights reserved.
//@"https://api.live.offcncloud.com/"//@"http://test-api.live.offcncloud.com/"
#ifndef ConfigrationNetwork_h
#define ConfigrationNetwork_h
//默认大班课开发模式接口
#define DEV_BASEURL @"http://im.offcncloud.com:8080"
#define DEV_IMAGEBASEURL @""
#define DEV_h5live @""
#define DEV_call_server_topic @""
//默认大班课测试模式接口
#define TEST_BASEURL @"http://test-im.offcncloud.com:8080"
#define TEST_IMAGEBASEURL @""
#define TEST_h5live @""
#define TEST_call_server_topic @""
//默认大班课生产模式接口
#define PRO_BASEURL @"http://im.offcncloud.com:8080"
#define PRO_IMAGEBASEURL @""
#define PRO_h5live @""
#define PRO_call_server_topic @""
//切换连麦call_server_topic
#define BASE_GetCallServerTopic_URL [OffcnBaseNetworking get_call_server_topic]
//切换域名
#define BASE_DOMAIN_URL [OffcnBaseNetworking get_BASEURL]
//图片的前缀
#define BASE_IMAGE_URL [OffcnBaseNetworking get_ImageBaseUrl]
//h5
#define BASE_H5_URL [OffcnBaseNetworking get_h5live]
#define BASE_URL [NSString stringWithFormat:@"%@/v1/",BASE_DOMAIN_URL]
#define BASE_USER_URL [NSString stringWithFormat:@"%@/user/",BASE_DOMAIN_URL]
#define HTTPS_IMAGEBASEURL @""
#pragma mark - 二级API
//发送消息
#define sendMsgURL [NSString stringWithFormat:@"%@sendMsg",BASE_URL]
//用户信息标记已读
#define markMsgReadURL [NSString stringWithFormat:@"%@markMsgRead",BASE_URL]
//获取会话未读消息列表
#define getSessionUnreadMsgURL [NSString stringWithFormat:@"%@getSessionUnreadMsg",BASE_URL]
//获取用户最近会话记录
#define getRecentSessionsURL [NSString stringWithFormat:@"%@getRecentSessions",BASE_URL]
//获取会话历史消息列表
#define getSessionHistoryMsgURL [NSString stringWithFormat:@"%@getSessionHistoryMsg",BASE_URL]
//获取七牛Token
#define uploadToken [NSString stringWithFormat:@"%@uploadToken",BASE_URL]
//注册用户设备
#define registerDevices [NSString stringWithFormat:@"%@devices/register",BASE_URL]
//注销用户设备
#define unregisterDevices [NSString stringWithFormat:@"%@devices/unregister",BASE_URL]
#endif /* ConfigrationNetwork_h */
++ /dev/null
//
// SDEnum.h
// OffcnIMSDKiOS
//
// Created by vockey on 2018/8/13.
// Copyright © 2018年 中公教育. All rights reserved.
//
#ifndef SDEnum_h
#define SDEnum_h
//typedef NS_ENUM(NSUInteger, OffcnSmallClassControllerType) {
// OffcnSmallClassControllerTypeDefaultTeaching = 0,//默认授课模式
// OffcnSmallClassControllerTypeStructureInside,//结构化场内模式
// OffcnSmallClassControllerTypeStructureOutside,//结构化场外模式
// OffcnSmallClassControllerTypeNoLeader,//无领导模式
//};
#endif /* SDEnum_h */
//
++ /dev/null
//
// GeneralDefine.h
//
//
#ifndef GeneralDefine_h
#define GeneralDefine_h
#define NSLog(format, ...) do { \
fprintf(stderr, "<%s : %d> %s\n", \
[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], \
__LINE__, __func__); \
(NSLog)((format), ##__VA_ARGS__); \
fprintf(stderr, "-------\n"); \
} while (0)
#undef NSLog
#if DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(FORMAT, ...)
#endif
#define KCustomerAPPKEY @"offcn_live"
#define KCustomerSecre @"offcn_im"
#pragma mark - 尺寸所有宏
#define Screen_Height [UIScreen mainScreen].bounds.size.height
#define Screen_Width [UIScreen mainScreen].bounds.size.width
#define kScreen_Height MAX(Screen_Width, Screen_Height)
#define kScreen_Width MIN(Screen_Width, Screen_Height)
//iphone6屏幕比例
#define KWidth_Scale kScreen_Width/375.0f
#define KKeyWindow [UIApplication sharedApplication].keyWindow
#define KFirstWindow [UIApplication sharedApplication].windows.firstObject
//判断是否有刘海
#define kIsIPhoneXSerious @available(iOS 11.0, *) && [UIApplication sharedApplication].windows.firstObject.safeAreaInsets.bottom > 0.0
#define kIsIphoneX kIsIPhoneXSerious
//iphoneX 竖屏安全区域顶部(如果导航栏是系统的写0就好)
#define kSafeAreaTopHeigth (kIsIphoneX?44:0)
//iphoneX 竖屏安全区域底部(如果导航栏是系统的写0就好)
#define kSafeAreaBottomHeigth (kIsIphoneX?34:0)
// 竖屏导航栏高度
#define kNavigationHeight (kIsIphoneX?88:64)
//竖屏状态栏
#define KStatusBarHeight (kIsIphoneX?44:20)
#define KFontNameBoldSize(f) [UIFont boldSystemFontOfSize:f]
#define KFontNameMediumSize(f) [UIFont systemFontOfSize:f]
#define KSetFont(size) [UIFont systemFontOfSize:size]
#define KImageNamed(name) [UIImage imageNamed:[NSString stringWithFormat:@"OffcnIMSDKiOS.bundle/%@",name]]
#define KEmojiImageNamed(name) [UIImage imageNamed:[NSString stringWithFormat:@"OffcnIMSDKiOS.bundle/emoji/%@",name]]
#define KWeakSelf __weak typeof(self) weakSelf = self;
/** 从RGB转换成UIColor (16进制->10进制)*/
#define kUIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
//****************设置颜色
#define UICOLOR_RGB_Alpha(_color,_alpha) [UIColor colorWithRed:((_color>>16)&0xff)/255.0f green:((_color>>8)&0xff)/255.0f blue:(_color&0xff)/255.0f alpha:_alpha]
#define random(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)/255.0]
#define randomColor random(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))
//小班课控制器的背景颜色
#define KOffcnSmallClassBackColor UICOLOR_RGB_Alpha(0x484d5c, 1)
//大班课控制器的背景颜色
#define KControllerBackColor UICOLOR_RGB_Alpha(0xf5f5f5, 1)
//直播状态
#define KRoomStateReasonsBackColor UICOLOR_RGB_Alpha(0x292929, 1)
//按钮普通状态
#define KButtonNormalColor UICOLOR_RGB_Alpha(0x333333, 1)
//按钮高亮状态
#define KButtonHighlightedColor UICOLOR_RGB_Alpha(0xFF5656, 1)
//按钮选中状态
#define KButtonSelectColor UICOLOR_RGB_Alpha(0xff895f, 1)
//按钮禁止状态
#define KButtonDisColor UICOLOR_RGB_Alpha(0xbfbfbf, 1)
//通知状态
#define KAlartBackColor UICOLOR_RGB_Alpha(0xffe6e0, 1)
//文字基本颜色
#define KTextColor UICOLOR_RGB_Alpha(0x333333, 1)
//标签文字基本颜色
#define KSubTagTextColor UICOLOR_RGB_Alpha(0x666666, 1)
//标签描边颜色
#define KSubTagLineColor UICOLOR_RGB_Alpha(0xcccccc, 1)
//副标题颜色
#define KSubTextColor UICOLOR_RGB_Alpha(0x999999, 1)
//人数颜色
#define KNumColor UICOLOR_RGB_Alpha(0x0d152d, 1)
//separatorColor颜色
#define KSeparatorColor UICOLOR_RGB_Alpha(0xe6e6e6, 1)
//textFiledplaceholder 文字颜色
#define KplaceholderLabelColor UICOLOR_RGB_Alpha(0xb3b3b3, 1)
//switch按钮颜色
#define KSwitchColor UICOLOR_RGB_Alpha(0x007aff, 1)
#define RGB(r, g, b) \
[UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
#define RGBA(r, g, b, a) \
[UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
////获取版本号
#define KAppVersion [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]
#define KUUIDString [UIDevice currentDevice].identifierForVendor.UUIDString
#define KRootTabBarController KKeyWindow.rootViewController
#define KUSERDEFAULT [NSUserDefaults standardUserDefaults]
//字符串是否为空
#define KStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )
//全字符串是否为空
#define KOffcnStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str isEqual: @"null"] || [str isEqual: @"<null>"] || [str isEqual: @"nil"] || [str length] < 1 ? YES : NO )
//数组是否为空
#define KArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)
/// View 圆角
#define ViewRadius(View, Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]
/// View加边框
#define ViewBorder(View, BorderColor, BorderWidth)\
\
View.layer.borderColor = BorderColor.CGColor;\
View.layer.borderWidth = BorderWidth;
//获取系统版本
#define XZSystemVersion ([UIDevice currentDevice].systemVersion.floatValue)
#define iOS11 (XZSystemVersion >= 11.0)
#define iOS10 (XZSystemVersion >= 10.0)
#define iOS9 (XZSystemVersion >= 9.0)
#define iOS8 (XZSystemVersion >= 8.0)
#define iOS7 (XZSystemVersion >= 7.0)
#define iOS6 (XZSystemVersion < 7.0)
/**
单例宏定义,可用可不用
*/
// .h文件
#define HHSingletonH(name) + (instancetype)shared##name;
// .m文件
#define HHSingletonM(name) \
static id _instance = nil; \
+ (id)allocWithZone:(struct _NSZone *)zone \
{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instance = [super allocWithZone:zone]; \
}); \
return _instance; \
} \
+ (instancetype)shared##name \
{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instance = [[self alloc] init]; \
}); \
return _instance; \
} \
- (id)copyWithZone:(NSZone *)zone \
{ \
return _instance; \
}
#endif /* GeneralDefine_h */
//
++ /dev/null
//
// SDKeyBoard.h
// OffcnIMSDKiOS
//
// Created by vockey on 2018/9/6.
// Copyright © 2018年 中公教育. All rights reserved.
//
#ifndef SDKeyBoard_h
#define SDKeyBoard_h
//mqtt通知
//#define kMQTTNotification @"kMQTTNotification"
#endif /* SDKeyBoard_h */
//
++ /dev/null
//
// AppDelegate+OffcnIMPush.m
// OffcnIMSDKiOS
//
// Created by vockey on 2020/9/1.
// Copyright © 2020 offcn. All rights reserved.
//
#import "AppDelegate+OffcnIMPush.h"
#import "OffcnIMModel.h"
#import "ZYJMJExtension.h"
#import "DataSafe.h"
#import "OffcnIMZYJFMDBHandler.h"
#import "OffcnIMSocketManager.h"
#import <UIKit/UIKit.h>
@implementation AppDelegate (OffcnIMPush)
+(void)registerOffcnUserNotificationSettingsWithApplication:(UIApplication *)application options:(NSDictionary *)launchOptions{
// application.applicationIconBadgeNumber = 0;
if ([UIDevice currentDevice].systemVersion.doubleValue >= 8.0){
// 1.请求授权可以给用户发送通知
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert categories:nil];
[application registerUserNotificationSettings:settings];
}else{
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
}
if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]){
NSDictionary *remoteUserInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
if(remoteUserInfo) {
NSLog(@"remoteUserInfo:%@",remoteUserInfo);
//APP未启动,点击推送消息,iOS10下还是跟以前一样在此获取
}
}
}
+(NSString *)hexStringForData:(NSData *)data{
if (data == nil) {
return nil;
}
NSMutableString *hexString = [NSMutableString string];
const unsigned char *p = [data bytes];
for (int i=0; i < [data length]; i++) {
[hexString appendFormat:@"%02x", *p++];
}
return hexString;
}
+(void)didReceiveRemoteNotification:(NSDictionary *)userInfo{
// {
// aps = {
// alert = {
// "action-loc-key" = "";
// body = "\U60a8\U6709\U4e00\U6761\U65b0\U7684\U6d88\U606f";
// "launch-image" = "";
// "loc-args" = "<null>";
// "loc-key" = "";
// title = "\U6d88\U606f\U901a\U77e5";
// "title-loc-args" = "<null>";
// "title-loc-key" = "";
// };
// };
// message = "{\"type\":1,\"body\":{\"session_id\":\"6e0f33004cb612a72341048b1eddbd3735e92dc4\",\"msg_id\":\"18fe84c6-25ea-41c7-9a70-1fe3e5c0b9ce\",\"version\":1,\"send_time\":\"2020-09-11 16:13:49\",\"msg_seq\":1599812029575,\"msg_from\":\"78f40cb49e0f54dd654de836c58f5202\",\"msg_to\":\"ce0819db8391f1e7258a71cc9e2c3235\",\"msg_scope\":1,\"msg_type\":1,\"msg\":{\"msg\":\"\U968f\U673a\U6570:9265\"}}}";
// }
OffcnIMPushModel *IMModel = [OffcnIMPushModel mj_ZYJobjectWithKeyValues:userInfo];
//存数据库
OffcnIMBodyModel *body = IMModel.message.body;
body.isSentSuccess = 1;
if ([body.msg_from isEqualToString:[OffcnIMSocketManager defaultService].msg_fromId]) {
body.bymyself = 1;
}else{
body.bymyself = 0;
}
body.isRead = 0;
[[OffcnIMZYJFMDBHandler sharedInstance] insertChatInfoToFMDBWithModel:body];
[[OffcnIMZYJFMDBHandler sharedInstance] chatlistCacheInfo:body callback:nil];
}
@end
//
++ /dev/null
//
// OffcnIMModel.m
// OffcnIMSDKiOS
//
// Created by vockey on 2020/8/25.
// Copyright © 2020 offcn. All rights reserved.
//
#import "OffcnIMModel.h"
@implementation OffcnIMModel
@end
@implementation OffcnIMBodyModel
@end
@implementation OffcnIMMsgModel
@end
@implementation OffcnIMSendMsgModel
@end
@implementation OffcnIMUnreadMsgModel
//+ (NSDictionary *)mj_ZYJreplacedKeyFromPropertyName {
// return @{
// @"ID":@"id",
// };
//}
+ (NSDictionary *)mj_ZYJobjectClassInArray{
return @{
@"msg_list" : @"OffcnIMBodyModel",
};
}
@end
@implementation OffcnIMRecentMsgModel
+ (NSDictionary *)mj_ZYJobjectClassInArray{
return @{
@"sessions" : @"OffcnIMSessionModel",
};
}
@end
@implementation OffcnIMSessionModel
@end
@implementation OffcnIMLast_msgModel
@end
@implementation OffcnIMHistoryMsgModel
+ (NSDictionary *)mj_ZYJobjectClassInArray{
return @{
@"msg_list" : @"OffcnIMBodyModel",
};
}
@end
@implementation OffcnIMPushModel
@end
@implementation OffcnIMPushApsModel
@end
#ifndef __OFFCN_IM__TYPES_H__
#define __OFFCN_IM__TYPES_H__
#include <stdio.h>
#ifdef _WIN32
#define ZG_OIM_API_EXPORT __declspec(dllexport)
#define ZG_OIM_API_IMPORT __declspec(dllimport)
#else
#define ZG_OIM_API_EXPORT __attribute__ ((visibility("default")))
#define ZG_OIM_API_IMPORT
#endif
#ifdef __cplusplus
#define ZG_OIM_C_API_EXPORT extern "C" ZG_OIM_API_EXPORT
#define ZG_OIM_C_API_IMPORT extern "C" ZG_OIM_API_IMPORT
#else
#define ZG_OIM_C_API_EXPORT ZG_OIM_API_EXPORT
#define ZG_OIM_C_API_IMPORT ZG_OIM_API_IMPORT
#endif
#ifdef ZG_OIM_SDK_EXPORTS //need define this micro,when build dll, undefine this micro when use this dll
#define ZG_OIM_C_API ZG_OIM_C_API_EXPORT
#else
#define ZG_OIM_C_API ZG_OIM_C_API_IMPORT
#endif
namespace offcn
{
namespace im
{
typedef enum
{
kMsg_Type_Normal, //正常的聊天消息
kMsg_Type_Recv_Confirm, //收到服务端发来的消息确认消息
}OImMsgType;
typedef enum
{
Z_CONN_IM_SRV_OK,
Z_CONN_IM_SRV_FAILED,
Z_CONN_IM_SRV_BROKEN,
Z_DISCONN_IM_SRV_OK,
}OImEventCode;
class OImCoreObserver
{
public:
virtual void OnOImCoreEvent(OImEventCode nEvent, int nCode, const char *context) = 0;
virtual void OnOImCoreMessage(const char *message, int len) = 0;
};
}
}
#endif
//
// OIMCore.h
//
// Created by zxl on 2020/8/7.
// Copyright © 2020 zxl. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "oim_types.h"
using namespace offcn::im;
@protocol OIMCoreDelegate <NSObject>
-(void)OnOImCoreMessageWithMessage:(const char *_Nonnull)message msgLength:(int)len;
-(void)OnOImCoreEventWithCode:(OImEventCode)code errorCode:(int)nErrorCode context:(const char *_Nonnull)context;
@end
NS_ASSUME_NONNULL_BEGIN
@interface OIMCoreAdapter : NSObject
@property(nonatomic, weak) id<OIMCoreDelegate> delegate;
+ (instancetype)sharedOIMCore;
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
- (id)copy NS_UNAVAILABLE;
- (id)mutableCopy NS_UNAVAILABLE;
- (void)Initialize;
/**
* connect to im server
*
* @param params must contain server'ip and port in json format eg:
* {"server_ip":"192.168.1.1", "server_port":123, "account_id":"123", "app_id":"123", "device_type":"windows", "token":"213", "account_id":"123", "session_id":"1223", "connection_type":"kcp"}
*/
-(void)ConnectImServerWithParam:(NSString*)param;
/**
* 与服务器断开连接
*/
-(void)DisConnectImServer;
/**
* 发送消息
*
* @param message message data, size less than 256 BYTES
* @param type message's type
*/
-(void)SendUserMessage:(NSString*)message length:(int)len type:(OImMsgType)type;
@end
NS_ASSUME_NONNULL_END
//
++ /dev/null
//
// DataSafe.h
// HomeHealth
//
// Created by newuser on 17/1/3.
// Copyright © 2017年 ChiJian. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface DataSafe : NSObject
@end
@interface NSNumber (safeCJ)
//防止类型错误出现崩溃
-(NSUInteger)length;
@end
@interface NSString (safeCJ)
//防止类型错误出现崩溃
-(NSString *)stringValue;
@end
@interface NSMutableArray (safeCJ)
-(void)addObjectOnSafe:(id)anObject;
@end
@interface NSArray (safeCJ)
-(id)objectAtIndexOnSafe:(NSUInteger)index;
@end
@interface NSMutableDictionary (safeCJ)
-(void)setObjectOnSafe:(id)anObject forKey:(id<NSCopying>)aKey;
@end
@interface NSDictionary (safeCJ)
- (NSString*)dictionaryToJson;
-(id)objectForKeyOnSafe:(id)aKey;
@end
//
++ /dev/null
//
// DataSafe.m
// HomeHealth
//
// Created by newuser on 17/1/3.
// Copyright © 2017年 ChiJian. All rights reserved.
//
#import "DataSafe.h"
@implementation DataSafe
@end
@implementation NSNumber (safeCJ)
//防止类型错误出现崩溃
-(NSUInteger)length{
return [self stringValue].length;
}
@end
@implementation NSString (safeCJ)
-(NSString *)stringValue{
return self;
}
@end
@implementation NSMutableArray (safeCJ)
-(void)addObjectOnSafe:(id)anObject{
if (!anObject) {
NSLog(@"warning:Array试图插入空对象");
return;
}
[self addObject:anObject];
}
@end
@implementation NSArray(safeCJ)
-(id)objectAtIndexOnSafe:(NSUInteger)index{
if (index >= self.count) {
return nil;
}
id obj = [self objectAtIndex:index];
return obj;
}
@end
@implementation NSMutableDictionary (safeCJ)
-(void)setObjectOnSafe:(id)anObject forKey:(id<NSCopying>)aKey{
if (!anObject || !aKey) {
NSLog(@"warning:Dictionary的试图对key--%@--字段置入空对象",aKey);
return;
}
[self setObject:anObject forKey:aKey];
}
@end
@implementation NSDictionary(safeCJ)
- (NSString*)dictionaryToJson{
NSError *parseError = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self options:NSJSONWritingPrettyPrinted error:&parseError];
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
-(id)objectForKeyOnSafe:(id)aKey{
if (!aKey) {
return nil;
}
id obj = [self objectForKey:aKey];
return obj;
}
@end
//
++ /dev/null
//
// NSDictionary+NullReplacement.h
// JinSeJiaYuanWang
//
// Created by honghong on 16/7/22.
// Copyright © 2016年 JYall Network Technology Co.,Ltd. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSDictionary (NullReplacement)
- (NSDictionary *)dictionaryByReplacingNullsWithBlanks;
@end
@interface NSArray (NullReplacement)
- (NSArray *)arrayByReplacingNullsWithBlanks;
@end
//
++ /dev/null
//
// NSDictionary+NullReplacement.m
// JinSeJiaYuanWang
//
// Created by honghong on 16/7/22.
// Copyright © 2016年 JYall Network Technology Co.,Ltd. All rights reserved.
//
#import "NSDictionary+NullReplacement.h"
@implementation NSDictionary (NullReplacement)
- (NSDictionary *)dictionaryByReplacingNullsWithBlanks {
const NSMutableDictionary *replaced = [self mutableCopy];
const id nul = [NSNull null];
const NSString *blank = @"";
for (NSString *key in self) {
id object = [self objectForKey:key];
if (object == nul) {
[replaced setObject:blank forKey:key];
} else if ([object isKindOfClass:[NSDictionary class]]) {
[replaced setObject:[object dictionaryByReplacingNullsWithBlanks] forKey:key];
} else if ([object isKindOfClass:[NSArray class]]) {
[replaced setObject:[object arrayByReplacingNullsWithBlanks] forKey:key];
}
}
return [NSDictionary dictionaryWithDictionary:[replaced copy]];
}
@end
@implementation NSArray (NullReplacement)
- (NSArray *)arrayByReplacingNullsWithBlanks {
NSMutableArray *replaced = [self mutableCopy];
const id nul = [NSNull null];
const NSString *blank = @"";
for (int idx = 0; idx < [replaced count]; idx++) {
id object = [replaced objectAtIndex:idx];
if (object == nul){
[replaced replaceObjectAtIndex:idx withObject:blank];
} else if ([object isKindOfClass:[NSDictionary class]]) {
[replaced replaceObjectAtIndex:idx withObject:[object dictionaryByReplacingNullsWithBlanks]];
} else if ([object isKindOfClass:[NSArray class]]) {
[replaced replaceObjectAtIndex:idx withObject:[object arrayByReplacingNullsWithBlanks]];
}
}
return [replaced copy];
}
@end
//
++ /dev/null
//
// NSFileManager+Paths.h
// iOS-Categories (https://github.com/shaojiankui/iOS-Categories)
//
// Created by Jakey on 14/12/30.
// Copyright (c) 2014年 www.skyfox.org. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSFileManager (Paths)
/**
Get URL of Documents directory.
@return Documents directory URL.
*/
+ (NSURL *)documentsURL;
/**
Get path of Documents directory.
@return Documents directory path.
*/
+ (NSString *)documentsPath;
/**
Get URL of Library directory.
@return Library directory URL.
*/
+ (NSURL *)libraryURL;
/**
Get path of Library directory.
@return Library directory path.
*/
+ (NSString *)libraryPath;
/**
Get URL of Caches directory.
@return Caches directory URL.
*/
+ (NSURL *)cachesURL;
/**
Get path of Caches directory.
@return Caches directory path.
*/
+ (NSString *)cachesPath;
/**
Adds a special filesystem flag to a file to avoid iCloud backup it.
@param path Path to a file to set an attribute.
*/
+ (BOOL)addSkipBackupAttributeToFile:(NSString *)path;
/**
Get available disk space.
@return An amount of available disk space in Megabytes.
*/
+ (double)availableDiskSpace;
@end
//
++ /dev/null
//
// NSFileManager+Paths.m
// iOS-Categories (https://github.com/shaojiankui/iOS-Categories)
//
// Created by Jakey on 14/12/30.
// Copyright (c) 2014年 www.skyfox.org. All rights reserved.
//
#import "NSFileManager+Paths.h"
#include <sys/xattr.h>
@implementation NSFileManager (Paths)
+ (NSURL *)URLForDirectory:(NSSearchPathDirectory)directory {
return [self.defaultManager URLsForDirectory:directory inDomains:NSUserDomainMask].lastObject;
}
+ (NSString *)pathForDirectory:(NSSearchPathDirectory)directory {
return NSSearchPathForDirectoriesInDomains(directory, NSUserDomainMask, YES)[0];
}
+ (NSURL *)documentsURL {
return [self URLForDirectory:NSDocumentDirectory];
}
+ (NSString *)documentsPath {
return [self pathForDirectory:NSDocumentDirectory];
}
+ (NSURL *)libraryURL {
return [self URLForDirectory:NSLibraryDirectory];
}
+ (NSString *)libraryPath {
return [self pathForDirectory:NSLibraryDirectory];
}
+ (NSURL *)cachesURL {
return [self URLForDirectory:NSCachesDirectory];
}
+ (NSString *)cachesPath {
return [self pathForDirectory:NSCachesDirectory];
}
+ (BOOL)addSkipBackupAttributeToFile:(NSString *)path {
return [[NSURL.alloc initFileURLWithPath:path] setResourceValue:@(YES) forKey:NSURLIsExcludedFromBackupKey error:nil];
}
+ (double)availableDiskSpace {
NSDictionary *attributes = [self.defaultManager attributesOfFileSystemForPath:self.documentsPath error:nil];
return [attributes[NSFileSystemFreeSize] unsignedLongLongValue] / (double)0x100000;
}
@end
//
++ /dev/null
//
// NSAttributedString+SDSize.h
// OffcnIMSDKiOS
//
// Created by vockey on 2018/8/23.
// Copyright © 2018年 中公教育. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface NSAttributedString (SDSize)
- (CGSize)sizeWithMaxSize:(CGSize)maxSize;
- (CGFloat)sizeWithMaxWidth:(CGFloat)maxWidth;
@end
++ /dev/null
//
// NSAttributedString+SDSize.m
// OffcnIMSDKiOS
//
// Created by vockey on 2018/8/23.
// Copyright © 2018年 中公教育. All rights reserved.
//
#import "NSAttributedString+SDSize.h"
@implementation NSAttributedString (SDSize)
#pragma mark 计算字符串大小
- (CGSize)sizeWithMaxSize:(CGSize)maxSize
{
CGSize textSize = [self boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:nil].size;
return textSize;
}
- (CGFloat)sizeWithMaxWidth:(CGFloat)maxWidth
{
CGSize textSize = [self boundingRectWithSize:CGSizeMake(maxWidth, 10000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:nil].size;
return textSize.height;
}
@end
//
++ /dev/null
//
// NSMutableAttributedString+SDSize.h
// OffcnIMSDKiOS
//
// Created by vockey on 2018/8/23.
// Copyright © 2018年 中公教育. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface NSMutableAttributedString (SDSize)
- (CGSize)sizeWithMaxSize:(CGSize)maxSize;
- (CGFloat)sizeWithMaxWidth:(CGFloat)maxWidth;
@end
//
++ /dev/null
//
// NSMutableAttributedString+SDSize.m
// OffcnIMSDKiOS
//
// Created by vockey on 2018/8/23.
// Copyright © 2018年 中公教育. All rights reserved.
//
#import "NSMutableAttributedString+SDSize.h"
@implementation NSMutableAttributedString (SDSize)
#pragma mark 计算字符串大小
- (CGSize)sizeWithMaxSize:(CGSize)maxSize
{
CGSize textSize = [self boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:nil].size;
return CGSizeMake(ceilf(textSize.width), ceilf(textSize.height));
}
- (CGFloat)sizeWithMaxWidth:(CGFloat)maxWidth
{
CGSize textSize = [self boundingRectWithSize:CGSizeMake(maxWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:nil].size;
return ceilf(textSize.height);
}
@end
++ /dev/null
#import <UIKit/UIKit.h>
@interface NSString (Extension)
- (CGSize)sizeWithFont:(UIFont *)font maxSize:(CGSize)maxSize;
- (CGFloat)sizeWithFont:(UIFont *)font maxWidth:(CGFloat)maxWidth;
//请求的时候给特殊字符转码
- (NSString *)URLEncodedString;
//给链接添加source=app
+ (NSString *)getAddSourceAppUrl:(NSString *)url;
//判断是否图片链接带http。返回正确的链接
+(NSString *)isHttpImageUrl:(NSString *)imageUrl;
//拆成数组再获取指定字符串
- (NSString *)subStringFromStartString:(NSString *)startString withSeparatedByString:(NSString *)str;
//截取字符串
- (NSString *)subStringFrom:(NSString *)startString to:(NSString *)endString;
@end
//
++ /dev/null
//
// NSString+Extension.m
//
// Created by xc on 15/3/6.
// Copyright (c) 2015年 xc. All rights reserved.
//
#import "NSString+Extension.h"
#import "OffcnBaseNetworking.h"
#import "SDConfigrationNetwork.h"
#import "SDGeneralDefine.h"
@implementation NSString (Extension)
#pragma mark 拆成数组再获取指定字符串
- (NSString *)subStringFromStartString:(NSString *)startString withSeparatedByString:(NSString *)str{
NSString *returnStr = @"";
NSArray *arr = [self componentsSeparatedByString:str];
for (int i=0; i<arr.count; i++) {
NSString *subStr = arr[i];
if ([subStr rangeOfString:startString].length) {
returnStr = [subStr substringFromIndex:startString.length];
break;
}
}
return returnStr;
}
#pragma mark 截取两个字符之间字符串
- (NSString *)subStringFrom:(NSString *)startString to:(NSString *)endString{
NSRange startRange = [self rangeOfString:startString];
NSRange endRange = [self rangeOfString:endString];
NSRange range = NSMakeRange(startRange.location + startRange.length, endRange.location - startRange.location - startRange.length);
return [self substringWithRange:range];
}
#pragma mark 计算字符串大小
- (CGSize)sizeWithFont:(UIFont *)font maxSize:(CGSize)maxSize
{
// NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
// paraStyle.lineSpacing = 6;
NSDictionary *dict = @{NSFontAttributeName: font,NSKernAttributeName:@0.0f};
CGSize textSize = [self boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:dict context:nil].size;
return textSize;
}
- (CGFloat)sizeWithFont:(UIFont *)font maxWidth:(CGFloat)maxWidth
{
// NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
// paraStyle.lineSpacing = 6;
//
// NSDictionary *dict = @{NSFontAttributeName: font,NSParagraphStyleAttributeName:paraStyle,NSKernAttributeName:@0.0f};
NSDictionary *dict = @{NSFontAttributeName: font,NSKernAttributeName:@0.0f};
CGSize textSize = [self boundingRectWithSize:CGSizeMake(maxWidth, 10000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:dict context:nil].size;
return textSize.height;
}
- (NSString *)URLEncodedString{
NSString *encodedString = (NSString *)
CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(CFStringRef)self,
(CFStringRef)@"!$&'()*+,-./:;=?@_~%#[]",
NULL,
kCFStringEncodingUTF8));
return encodedString;
}
+ (NSString *)getAddSourceAppUrl:(NSString *)url{
NSString *retUrl;
if ([url containsString:@"?source=app"]) {
retUrl = url;
}else if ([url containsString:@"?"]){
retUrl = [url stringByAppendingString:@"&source=app"];
}else{
retUrl = [url stringByAppendingString:@"?source=app"];
}
retUrl = [NSString CustomAddUrl:retUrl];
return retUrl;
}
//判断是否图片链接带http。返回正确的链接
+(NSString *)isHttpImageUrl:(NSString *)imageUrl{
if ([imageUrl containsString:@"http"]) {
return imageUrl;
}
return [BASE_IMAGE_URL stringByAppendingString:imageUrl];
}
#pragma mark 链接新添加的
+ (NSString *)CustomAddUrl:(NSString *)url{
NSString *appkeyParam = [NSString stringWithFormat:@"APPkey=%@",KCustomerAPPKEY];
// NSString *deviceIdParam = [NSString stringWithFormat:@"deviceid=%@",[UMSAgent getUMSUDID]];
// NSString *appendStr = [NSString stringWithFormat:@"%@&%@&%@",url,appkeyParam,deviceIdParam];
// NSString *userId = [[[CommonManager shareInstance] getAccount] userId];
// if ([userId length] > 0) {
// appendStr = [appendStr stringByAppendingFormat:@"&userId=%@",userId];
// }
return appkeyParam;
}
@end
//
++ /dev/null
//
// NSString+JSON.h
// JinSeJiaYuanWang
//
// Created by honghong on 16/3/21.
// Copyright © 2016年 JYall Network Technology Co.,Ltd. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSString (JSON)
+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString;
+ (NSString*)dictonaryTOjsonString:(id)object;
@end
//
++ /dev/null
//
// NSString+JSON.m
// JinSeJiaYuanWang
//
// Created by honghong on 16/3/21.
// Copyright © 2016年 JYall Network Technology Co.,Ltd. All rights reserved.
//
#import "NSString+JSON.h"
@implementation NSString (JSON)
+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString
{
if (jsonString == nil) {return nil;}
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];NSError *err;
NSDictionary *dic= [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
if(err) {
NSLog(@"json解析失败:%@",err);
return nil;
}
return dic;
}
+(NSString*)dictonaryTOjsonString:(id)object
{
NSString *jsonString = nil;
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object
options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
error:&error];
if (! jsonData) {
NSLog(@"Got an error: %@", error);
} else {
jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
return jsonString;
}
+ (NSString*)dictionaryToJson:(NSDictionary *)dic
{
NSError *parseError = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
@end
//
++ /dev/null
//
// NSString+MD5Encrypt.h
// Smile
//
// Created by 周 敏 on 12-11-24.
//
#import <CommonCrypto/CommonDigest.h>
#import <Foundation/Foundation.h>
@interface NSString (MD5)
- (NSString *)md5Encrypt;
@end
//
++ /dev/null
//
// NSString+MD5Encrypt.h
// Smile
//
// Created by 周 敏 on 12-11-24.
//
#import "NSString+MD5.h"
@implementation NSString (MD5)
- (NSString *)md5Encrypt
{
const char *cStr = [self UTF8String];
unsigned char result[16];
CC_MD5( cStr, (CC_LONG)strlen(cStr), result );
return [NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
result[0], result[1], result[2], result[3],
result[4], result[5], result[6], result[7],
result[8], result[9], result[10], result[11],
result[12], result[13], result[14], result[15]
];
}
@end
//
++ /dev/null
//
// JYButton.h
// 张云杰
//
// Created by mac on 16/3/13.
// Copyright © 2016年 com.jyall. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface JYButton : UIButton
+ (JYButton *)initWithTitle:(NSString *)title norImage:(NSString *)norImage higImage:(NSString *)higImage targert:(id)targert action:(SEL)action;
+ (JYButton *)initWithNorBackgroundImage:(NSString *)norBackgroundImage higBackgroundImage:(NSString *)higBackgroundImage targert:(id)targert action:(SEL)action;
@end
//
++ /dev/null
//
// JYButton.m
// 张云杰
//
// Created by mac on 16/3/13.
// Copyright © 2016年 com.jyall. All rights reserved.
//
#import "JYButton.h"
#import "SDGeneralDefine.h"
@implementation JYButton
+ (JYButton *)initWithTitle:(NSString *)title norImage:(NSString *)norImage higImage:(NSString *)higImage targert:(id)targert action:(SEL)action{
JYButton *btn = [[self alloc]init];
if (norImage != nil && ![norImage isEqualToString:@""]) {
[btn setImage:KImageNamed(norImage) forState:UIControlStateNormal];
}
if (higImage != nil && ![higImage isEqualToString:@""]) {
[btn setImage:KImageNamed(higImage) forState:UIControlStateHighlighted];
}
if (title != nil && ![title isEqualToString:@""]) {
[btn setTitle:title forState:UIControlStateNormal];
}
[btn sizeToFit];
[btn addTarget:targert action:action forControlEvents:UIControlEventTouchUpInside];
return btn;
}
+ (JYButton *)initWithNorBackgroundImage:(NSString *)norBackgroundImage higBackgroundImage:(NSString *)higBackgroundImage targert:(id)targert action:(SEL)action{
JYButton *btn = [self buttonWithType:UIButtonTypeCustom];
if (norBackgroundImage != nil && ![norBackgroundImage isEqualToString:@""]) {
[btn setBackgroundImage:KImageNamed(norBackgroundImage) forState:UIControlStateNormal];
}
if (higBackgroundImage != nil && ![higBackgroundImage isEqualToString:@""]) {
[btn setBackgroundImage:KImageNamed(higBackgroundImage) forState:UIControlStateSelected];
}
[btn sizeToFit];
[btn addTarget:targert action:action forControlEvents:UIControlEventTouchDown];
return btn;
}
// 让按钮在高亮的状态不要做其他操作
- (void)setHighlighted:(BOOL)highlighted
{
//[super setHighlighted:highlighted];
}
@end
//
++ /dev/null
//
// SDButton.h
// OffcnIMSDKiOS
//
// Created by vockey on 2018/7/31.
// Copyright © 2018年 中公教育. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface SDButton : UIButton
+ (SDButton *)initWithTitle:(NSString *)title norImage:(NSString *)norImage higImage:(NSString *)higImage targert:(id)targert action:(SEL)action;
+ (SDButton *)initWithTitle:(NSString *)title norImage:(NSString *)norImage higImage:(NSString *)higImage offset:(CGFloat)offset targert:(id)targert action:(SEL)action;
+ (SDButton *)initWithNorBackgroundImage:(NSString *)norBackgroundImage higBackgroundImage:(NSString *)higBackgroundImage targert:(id)targert action:(SEL)action;
@end
//
++ /dev/null
//
// SDButton.m
// OffcnIMSDKiOS
//
// Created by vockey on 2018/7/31.
// Copyright © 2018年 中公教育. All rights reserved.
//
#import "SDButton.h"
#import "SDGeneralDefine.h"
@implementation SDButton
+ (SDButton *)initWithTitle:(NSString *)title norImage:(NSString *)norImage higImage:(NSString *)higImage targert:(id)targert action:(SEL)action{
SDButton *btn = [[self alloc]init];
if (norImage != nil && ![norImage isEqualToString:@""]) {
[btn setImage:KImageNamed(norImage) forState:UIControlStateNormal];
}
if (higImage != nil && ![higImage isEqualToString:@""]) {
[btn setImage:KImageNamed(higImage) forState:UIControlStateHighlighted];
}
if (title != nil && ![title isEqualToString:@""]) {
[btn setTitle:title forState:UIControlStateNormal];
}
[btn sizeToFit];
[btn addTarget:targert action:action forControlEvents:UIControlEventTouchUpInside];
return btn;
}
+ (SDButton *)initWithTitle:(NSString *)title norImage:(NSString *)norImage higImage:(NSString *)higImage offset:(CGFloat)offset targert:(id)targert action:(SEL)action{
SDButton *btn = [[self alloc] init];
[btn setBackgroundImage:KImageNamed(@"SDVideo_tiwen_beijing") forState:UIControlStateNormal];
if (norImage != nil && ![norImage isEqualToString:@""]) {
[btn setImage:KImageNamed(norImage) forState:UIControlStateNormal];
}
if (higImage != nil && ![higImage isEqualToString:@""]) {
[btn setImage:KImageNamed(higImage) forState:UIControlStateHighlighted];
}
[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
btn.titleLabel.font = KFontNameMediumSize(10);
btn.titleLabel.textAlignment = NSTextAlignmentCenter;
if (title != nil && ![title isEqualToString:@""]) {
[btn setTitle:title forState:UIControlStateNormal];
}
btn.titleEdgeInsets = UIEdgeInsetsMake(0, -btn.imageView.intrinsicContentSize.width, -btn.imageView.intrinsicContentSize.height- offset/2.0, 0);
btn.imageEdgeInsets = UIEdgeInsetsMake(-btn.titleLabel.intrinsicContentSize.height- offset/2.0, 0, 0, -btn.titleLabel.intrinsicContentSize.width);
[btn addTarget:targert action:action forControlEvents:UIControlEventTouchUpInside];
return btn;
}
+ (SDButton *)initWithNorBackgroundImage:(NSString *)norBackgroundImage higBackgroundImage:(NSString *)higBackgroundImage targert:(id)targert action:(SEL)action{
SDButton *btn = [self buttonWithType:UIButtonTypeCustom];
if (norBackgroundImage != nil && ![norBackgroundImage isEqualToString:@""]) {
[btn setBackgroundImage:KImageNamed(norBackgroundImage) forState:UIControlStateNormal];
}
if (higBackgroundImage != nil && ![higBackgroundImage isEqualToString:@""]) {
[btn setBackgroundImage:KImageNamed(higBackgroundImage) forState:UIControlStateSelected];
}
[btn sizeToFit];
[btn addTarget:targert action:action forControlEvents:UIControlEventTouchDown];
return btn;
}
@end
//
++ /dev/null
//
// UIBarButtonItem+WNXBarButtonItem.h
// WNXHuntForCity
//
// Created by MacBook on 15/6/29.
// Copyright (c) 2015年 维尼的小熊. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIBarButtonItem (WNXBarButtonItem)
+ (UIBarButtonItem *)initWithNormalImage:(NSString *)image target:(id)target size:(CGSize)size isLeftButton:(BOOL)isleft action:(SEL)action;
/**
* 根据图片快速创建一个UIBarButtonItem,返回小号barButtonItem
*/
+ (UIBarButtonItem *)initWithNormalImage:(NSString *)image target:(id)target isLeftButton:(BOOL)isleft action:(SEL)action;
/**
*根据图片快速创建一个UIBarButtonItem,返回大号barButtonItem
*/
+ (UIBarButtonItem *)initWithNormalImageBig:(NSString *)image target:(id)target action:(SEL)action;
/**
*根据图片快速创建一个UIBarButtonItem,自定义大小
*/
+ (UIBarButtonItem *)initWithNormalImage:(NSString *)image target:(id)target action:(SEL)action width:(CGFloat)width height:(CGFloat)height;
//创建有图片,有文字的
+ (UIBarButtonItem *)initWithNormalImage:(NSString *)image title:(NSString *)title target:(id)target action:(SEL)action;
/**
*根据文字快速创建一个UIBarButtonItem,自定义大小
*/
+ (UIBarButtonItem *)initWithTitle:(NSString *)title titleColor:(UIColor *)titleColor target:(id)target action:(SEL)action;
@end
//
++ /dev/null
//
// UIBarButtonItem+WNXBarButtonItem.m
// WNXHuntForCity
//
// Created by MacBook on 15/6/29.
// Copyright (c) 2015年 维尼的小熊. All rights reserved.
//
#import "UIBarButtonItem+WNXBarButtonItem.h"
#import "SDGeneralDefine.h"
@implementation UIBarButtonItem (WNXBarButtonItem)
+ (UIBarButtonItem *)initWithNormalImage:(NSString *)image target:(id)target size:(CGSize)size isLeftButton:(BOOL)isleft action:(SEL)action
{
UIImage *normalImage = KImageNamed(image);
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 0, size.width, size.height);
btn.imageView.contentMode = UIViewContentModeScaleAspectFit;
if (isleft) {
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
}else{
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
}
// button.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
// [btn setBackgroundImage:normalImage forState:UIControlStateNormal];
[btn setImage:normalImage forState:UIControlStateNormal];
[btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
return [[UIBarButtonItem alloc] initWithCustomView:btn];
}
+ (UIBarButtonItem *)initWithNormalImage:(NSString *)image target:(id)target isLeftButton:(BOOL)isleft action:(SEL)action
{
UIImage *normalImage = KImageNamed(image);
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 0, 30, 30);
btn.imageView.contentMode = UIViewContentModeScaleAspectFit;
if (isleft) {
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
}else{
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
}
// button.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
// [btn setBackgroundImage:normalImage forState:UIControlStateNormal];
[btn setImage:normalImage forState:UIControlStateNormal];
[btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
return [[UIBarButtonItem alloc] initWithCustomView:btn];
}
+ (UIBarButtonItem *)initWithNormalImage:(NSString *)image title:(NSString *)title target:(id)target action:(SEL)action
{
UIImage *normalImage = KImageNamed(image);
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setImage:normalImage forState:UIControlStateNormal];
[btn setTitle:title forState:UIControlStateNormal];
// CGSize titleSize = [titleSize bo]
// UIFont *temp1 = [UIFont fontWithName:@"Helvetica Neue" size:12];
btn.titleLabel.font = [UIFont systemFontOfSize:14];
// NSDictionary *attributes = @{NSFontAttributeName:label3.font};
[btn.titleLabel sizeThatFits:CGSizeMake(100, 20)];
CGSize size = [title sizeWithAttributes: [NSDictionary dictionaryWithObjectsAndKeys:btn.titleLabel.font,NSFontAttributeName,nil]];
btn.frame = CGRectMake(0, 0, size.width+15, 30);
btn.imageView.contentMode = UIViewContentModeScaleAspectFit;
// [btn setBackgroundImage:normalImage forState:UIControlStateNormal];
[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -size.width-25);
btn.titleEdgeInsets = UIEdgeInsetsMake(0, -size.width-5, 0, 0);
[btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
return [[UIBarButtonItem alloc] initWithCustomView:btn];
}
+ (UIBarButtonItem *)initWithNormalImageBig:(NSString *)image target:(id)target action:(SEL)action
{
UIImage *normalImage = KImageNamed(image);
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 0, 35, 35);
[btn setBackgroundImage:normalImage forState:UIControlStateNormal];
[btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
return [[UIBarButtonItem alloc] initWithCustomView:btn];
}
+ (UIBarButtonItem *)initWithNormalImage:(NSString *)image target:(id)target action:(SEL)action width:(CGFloat)width height:(CGFloat)height
{
UIImage *normalImage = KImageNamed(image);
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 0, width, height);
[btn setBackgroundImage:normalImage forState:UIControlStateNormal];
[btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
return [[UIBarButtonItem alloc] initWithCustomView:btn];
}
+ (UIBarButtonItem *)initWithTitle:(NSString *)title titleColor:(UIColor *)titleColor target:(id)target action:(SEL)action
{
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 0, 35, 35);
btn.titleLabel.font = [UIFont systemFontOfSize:15];
btn.titleLabel.textAlignment = NSTextAlignmentRight;
[btn setTitle:title forState:UIControlStateNormal];
if (!titleColor) {
titleColor = [UIColor blackColor];
}
[btn setTitleColor:titleColor forState:UIControlStateNormal];
[btn setTitleColor:UICOLOR_RGB_Alpha(0xcccccc, 1) forState:UIControlStateDisabled];
[btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:btn];
return item;
}
@end
//
++ /dev/null
//
// UIColor+applianceHex.h
// 张云杰
//
// Created by mac on 16/3/13.
// Copyright © 2016年 com.jyall. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIColor (applianceHex)
/*
* 输入6位数返回一个颜色值
*/
+ (UIColor *)colorFromHex:(NSString *)hex;
/*
* 输入6位数和透明度返回一个颜色值
*/
+ (UIColor *)colorFromHex:(NSString *)hex alpha:(CGFloat)alpha;
//背景
+ (UIColor *)colorBackWithBackView;
//主题
+ (UIColor *)colorTheme;
//虚线
+ (UIColor *)colorLine;
//文字
+ (UIColor *)colorTextBlack;
//未输入颜色
+ (UIColor *)colorPlaceholderTextBlack;
//按钮边框颜色
+ (UIColor *)colorcornerRadiusBtnLayerBlack;
@end
//
++ /dev/null
//
// UIColor+applianceHex.m
// 张云杰
//
// Created by mac on 16/3/13.
// Copyright © 2016年 com.jyall. All rights reserved.
//
#import "UIColor+applianceHex.h"
@implementation UIColor (applianceHex)
+ (UIColor *)colorFromHex:(NSString *)hex
{
return [UIColor colorFromHex:hex alpha:1.0];
}
+ (UIColor *)colorFromHex:(NSString *)hex alpha:(CGFloat)alpha
{
NSString *cleanString = [hex stringByReplacingOccurrencesOfString:@"#" withString:@""];
if([cleanString length] == 3) {
cleanString = [NSString stringWithFormat:@"%@%@%@%@%@%@",
[cleanString substringWithRange:NSMakeRange(0, 1)],[cleanString substringWithRange:NSMakeRange(0, 1)],
[cleanString substringWithRange:NSMakeRange(1, 1)],[cleanString substringWithRange:NSMakeRange(1, 1)],
[cleanString substringWithRange:NSMakeRange(2, 1)],[cleanString substringWithRange:NSMakeRange(2, 1)]];
}
if([cleanString length] == 6) {
cleanString = [cleanString stringByAppendingString:@"ff"];
}
unsigned int baseValue;
[[NSScanner scannerWithString:cleanString] scanHexInt:&baseValue];
float red = ((baseValue >> 24) & 0xFF)/255.0f;
float green = ((baseValue >> 16) & 0xFF)/255.0f;
float blue = ((baseValue >> 8) & 0xFF)/255.0f;
return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}
#pragma mark - #
+ (UIColor *)colorBackWithBackView{
return [UIColor colorFromHex:@"#f8f8f8"];
}
+ (UIColor *)colorTheme{
return [UIColor colorFromHex:@"#00a0e9"];
}
+ (UIColor *)colorLine{
return [UIColor colorFromHex:@"#dcdcdc"];
}
+ (UIColor *)colorTextBlack{
return [UIColor colorFromHex:@"#333333"];
}
+ (UIColor *)colorPlaceholderTextBlack{
return [UIColor colorFromHex:@"#999999"];
}
+ (UIColor *)colorcornerRadiusBtnLayerBlack{
return [UIColor colorFromHex:@"#f8b851"];
}
@end
//
++ /dev/null
//
// UIImage+Color.h
// JYallXiangMuTong
//
// Created by 葬花桥 on 16/1/4.
// Copyright © 2016年 陈石. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIImage (Color)
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size;
//给我一种颜色,一个尺寸,我给你返回一个UIImage:不透明
+(UIImage *)imageFromContextWithColor:(UIColor *)color;
+(UIImage *)imageFromContextWithColor:(UIColor *)color size:(CGSize)size;
@end
//
++ /dev/null
//
// UIImage+Color.m
// JYallXiangMuTong
//
// Created by 葬花桥 on 16/1/4.
// Copyright © 2016年 陈石. All rights reserved.
//
#import "UIImage+Color.h"
@implementation UIImage (Color)
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size
{
CGRect rect = CGRectMake(0, 0, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
//给我一种颜色,一个尺寸,我给你返回一个UIImage
+(UIImage *)imageFromContextWithColor:(UIColor *)color size:(CGSize)size{
CGRect rect=(CGRect){{0.0f,0.0f},size};
//开启一个图形上下文
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0f);
//获取图形上下文
CGContextRef context=UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, rect);
//获取图像
UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
//关闭上下文
UIGraphicsEndImageContext();
return image;
}
+(UIImage *)imageFromContextWithColor:(UIColor *)color{
CGSize size=CGSizeMake(1.0f, 1.0f);
return [self imageFromContextWithColor:color size:size];
}
@end
++ /dev/null
#import <UIKit/UIKit.h>
@interface UIImage (Extension)
/**
* 圆形剪裁图片
*
* @param borderW 圆环宽度
* @param color 圆环颜色
* @param imageName 图片名称
*
* @return 剪裁好的图片
*/
+ (UIImage *)imageWithBorderW:(CGFloat)borderW color:(UIColor *)color CircleImageName:(NSString *)imageName;
//- (instancetype)yzt_drawRectWithRoundCorner:(UIRectCorner)rectCorner radius:(CGFloat)radius size:(CGSize)size;
+ (UIImage *)resizableImageWithName:(NSString *)imageName;
+ (UIImage *) imageWithName:(NSString *) imageName;
- (UIImage*) scaleImageWithSize:(CGSize)size;
- (UIImage*) scaleImageWithFrame:(CGRect)frame;
+ (UIImage *)thumbnailWithImageWithoutScale:(UIImage *)image size:(CGSize)asize;
//图片image旋转
+ (UIImage *)offcnImage:(UIImage *)image rotation:(UIImageOrientation)orientation;
@end
++ /dev/null
#import "UIImage+Extension.h"
#import "SDGeneralDefine.h"
@implementation UIImage (Extension)
+ (UIImage *)imageWithBorderW:(CGFloat)borderW color:(UIColor *)color CircleImageName:(NSString *)imageName
{
UIImage *img = KImageNamed(imageName);
CGFloat w = img.size.width + 2 * borderW;
CGFloat h = img.size.height + 2 * borderW;
CGRect bigCricleRect = CGRectMake(0, 0, w, h);
// 1.开启位图上下文
UIGraphicsBeginImageContextWithOptions(bigCricleRect.size, NO, 0);
// 2.拼接路径
// 2.1绘制大圆
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:bigCricleRect];
// 设置圆环颜色
[color set];
[path fill];
// 2.2设置裁剪区域
CGRect clipRect = CGRectMake(borderW, borderW, img.size.width, img.size.height);
// 描述裁剪区域路径
UIBezierPath *clipPath = [UIBezierPath bezierPathWithOvalInRect:clipRect];
[clipPath addClip];
// 绘制图片
[img drawAtPoint:CGPointMake(borderW, borderW)];
// 获取图片
img = UIGraphicsGetImageFromCurrentImageContext();
// 关闭上下文
UIGraphicsEndImageContext();
return img;
}
- (UIImage *)drawCircleImage {
// UIImage *img = KImageNamed(imageName);
// CGFloat w = img.size.width + 2 * borderW;
// CGFloat h = img.size.height + 2 * borderW;
// CGRect bigCricleRect = CGRectMake(0, 0, w, h);
CGRect rect = CGRectMake(0, 0, 50, 50);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, [UIScreen mainScreen].scale);
[[UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:50] addClip];
[self drawInRect:rect];
UIImage *output = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return output;
}
+ (UIImage *)resizableImageWithName:(NSString *)imageName{
UIImage *image = KImageNamed(imageName);
// 获取原有图片的宽高的一半
CGFloat w = image.size.width * 0.5;
CGFloat h = image.size.height * 0.5;
// 生成可以拉伸指定位置的图片
UIImage *newImage = [image resizableImageWithCapInsets:UIEdgeInsetsMake(h, w, h, w) resizingMode:UIImageResizingModeStretch];
return newImage;
}
/**
* 争对ios7以上的系统适配新的图片资源
*
* @param imageName 图片名称
*
* @return 新的图片
*/
+ (UIImage *)imageWithName:(NSString *)imageName
{
UIImage *newImage = nil;
if (newImage == nil) {
newImage = KImageNamed(imageName);
}
return newImage;
}
/**
* 实现图片的缩小或者放大
*
* @param size 大小范围
*
* @return 新的图片
*/
-(UIImage*) scaleImageWithSize:(CGSize)size
{
UIGraphicsBeginImageContextWithOptions(size,NO,0); //size 为CGSize类型,即你所需要的图片尺寸
[self drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage; //返回的就是已经改变的图片
}
- (UIImage*) scaleImageWithFrame:(CGRect)frame{
UIGraphicsBeginImageContextWithOptions(frame.size,NO,0); //size 为CGSize类型,即你所需要的图片尺寸
[self drawInRect:frame];
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage; //返回的就是已经改变的图片
}
+ (UIImage *)thumbnailWithImageWithoutScale:(UIImage *)image size:(CGSize)asize
{
UIImage *newimage;
if (nil == image)
{
newimage = nil;
} else {
CGSize oldsize = image.size;
CGRect rect;
if (asize.width/asize.height > oldsize.width/oldsize.height)
{
rect.size.width = asize.height*oldsize.width/oldsize.height;
rect.size.height = asize.height;
rect.origin.x = (asize.width - rect.size.width)/2;
rect.origin.y = 0;
} else {
rect.size.width = asize.width;
rect.size.height = asize.width*oldsize.height/oldsize.width;
rect.origin.x = 0;
rect.origin.y = (asize.height - rect.size.height)/2;
}
UIGraphicsBeginImageContext(asize);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
UIRectFill(CGRectMake(0, 0, asize.width, asize.height));//clear background
[image drawInRect:rect];
newimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
return newimage;
}
//图片image旋转
+ (UIImage *)offcnImage:(UIImage *)image rotation:(UIImageOrientation)orientation{
long double rotate = 0.0;
CGRect rect;
float translateX = 0;
float translateY = 0;
float scaleX = 1.0;
float scaleY = 1.0;
switch (orientation) {
case UIImageOrientationLeft:
rotate = M_PI_2;
rect = CGRectMake(0, 0, image.size.height, image.size.width);
translateX = 0;
translateY = -rect.size.width;
scaleY = rect.size.width/rect.size.height;
scaleX = rect.size.height/rect.size.width;
break;
case UIImageOrientationRight:
rotate = 3 * M_PI_2;
rect = CGRectMake(0, 0, image.size.height, image.size.width);
translateX = -rect.size.height;
translateY = 0;
scaleY = rect.size.width/rect.size.height;
scaleX = rect.size.height/rect.size.width;
break;
case UIImageOrientationDown:
rotate = M_PI;
rect = CGRectMake(0, 0, image.size.width, image.size.height);
translateX = -rect.size.width;
translateY = -rect.size.height;
break;
default:
rotate = 0.0;
rect = CGRectMake(0, 0, image.size.width, image.size.height);
translateX = 0;
translateY = 0;
break;
}
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
//做CTM变换
CGContextTranslateCTM(context, 0.0, rect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextRotateCTM(context, rotate);
CGContextTranslateCTM(context, translateX, translateY);
CGContextScaleCTM(context, scaleX, scaleY);
//绘制图片
CGContextDrawImage(context, CGRectMake(0, 0, rect.size.width, rect.size.height), image.CGImage);
UIImage *newPic = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newPic;
}
@end
++ /dev/null
//
// SDLabel.m
// OffcnIMSDKiOS
//
// Created by vockey on 2018/8/8.
// Copyright © 2018年 中公教育. All rights reserved.
//
#import "SDLabel.h"
#import "SDGeneralDefine.h"
@implementation SDLabel
- (instancetype)initWithFrame:(CGRect)frame
{
if(self = [super initWithFrame:frame])
{
self.edgeInsets = UIEdgeInsetsMake(15*KWidth_Scale, 0, 15*KWidth_Scale, 0);
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder]) {
self.edgeInsets = UIEdgeInsetsMake(15*KWidth_Scale, 0, 15*KWidth_Scale, 0);
}
return self;
}
- (void)awakeFromNib
{
[super awakeFromNib];
self.edgeInsets = UIEdgeInsetsMake(15*KWidth_Scale, 0, 15*KWidth_Scale, 0);
}
// 修改绘制文字的区域,edgeInsets增加bounds
-(CGRect)textRectForBounds:(CGRect)bounds
limitedToNumberOfLines:(NSInteger)numberOfLines
{
/*
调用父类该方法
注意传入的UIEdgeInsetsInsetRect(bounds, self.edgeInsets),bounds是真正的绘图区域
*/
CGRect rect = [super textRectForBounds:UIEdgeInsetsInsetRect(bounds,
self.edgeInsets) limitedToNumberOfLines:numberOfLines];
//根据edgeInsets,修改绘制文字的bounds
rect.origin.x -= self.edgeInsets.left;
rect.origin.y -= self.edgeInsets.top;
rect.size.width += self.edgeInsets.left + self.edgeInsets.right;
rect.size.height += self.edgeInsets.top + self.edgeInsets.bottom;
return rect;
}
//绘制文字
- (void)drawTextInRect:(CGRect)rect
{
//令绘制区域为原始区域,增加的内边距区域不绘制
[super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.edgeInsets)];
}
@end
//
++ /dev/null
//
// Slider.h
// CLPlayerDemo
//
// Created by JmoVxia on 2016/11/2.
// Copyright © 2016年 JmoVxia. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface CLSlider : UISlider
@property (nonatomic, copy) void(^tapValueCallAction)(CLSlider *slider);
@end
//
++ /dev/null
//
// Slider.m
// CLPlayerDemo
//
// Created by JmoVxia on 2016/11/2.
// Copyright © 2016年 JmoVxia. All rights reserved.
//
#import "CLSlider.h"
#import "SDGeneralDefine.h"
#define SLIDER_X_BOUND 30
#define SLIDER_Y_BOUND 40
@interface CLSlider ()
/**lastBounds*/
@property (nonatomic,assign) CGRect lastBounds;
@end
@implementation CLSlider
-(instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
[self setup];
}
return self;
}
-(void)sliderTap:(UIGestureRecognizer *)tap{
CGPoint point = [tap locationInView:self];
CGFloat value = point.x/self.bounds.size.width;
if (value>0 && value<=1) {
[self setValue:value animated:YES];
if (self.tapValueCallAction) {
self.tapValueCallAction(self);
}
}
}
- (void)setup {
UIImage *thumbImage = KImageNamed(@"SDVideo_progress_dian");
[self setThumbImage:thumbImage forState:UIControlStateHighlighted];
[self setThumbImage:thumbImage forState:UIControlStateNormal];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sliderTap:)];
[self addGestureRecognizer:tap];
}
// 控制slider的宽和高,这个方法才是真正的改变slider滑道的高的
- (CGRect)trackRectForBounds:(CGRect)bounds{
[super trackRectForBounds:bounds];
return CGRectMake(bounds.origin.x, bounds.origin.y, CGRectGetWidth(bounds), 2);
}
//修改滑块位置
- (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value {
rect.origin.x = rect.origin.x - 6 ;
rect.size.width = rect.size.width + 12;
CGRect result = [super thumbRectForBounds:bounds trackRect:rect value:value];
//记录下最终的frame
_lastBounds = result;
return result;
}
//检查点击事件点击范围是否能够交给self处理
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
//调用父类方法,找到能够处理event的view
UIView* result = [super hitTest:point withEvent:event];
if (result != self) {
/*如果这个view不是self,我们给slider扩充一下响应范围,
这里的扩充范围数据就可以自己设置了
*/
if ((point.y >= -15) &&
(point.y < (_lastBounds.size.height + SLIDER_Y_BOUND)) &&
(point.x >= 0 && point.x < CGRectGetWidth(self.bounds))) {
//如果在扩充的范围类,就将event的处理权交给self
result = self;
}
}
//否则,返回能够处理的view
return result;
}
//检查是点击事件的点是否在slider范围内
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
//调用父类判断
BOOL result = [super pointInside:point withEvent:event];
if (!result) {
//同理,如果不在slider范围类,扩充响应范围
if ((point.x >= (_lastBounds.origin.x - SLIDER_X_BOUND)) && (point.x <= (_lastBounds.origin.x + _lastBounds.size.width + SLIDER_X_BOUND))
&& (point.y >= -SLIDER_Y_BOUND) && (point.y < (_lastBounds.size.height + SLIDER_Y_BOUND))) {
//在扩充范围内,返回yes
result = YES;
}
}
//否则返回父类的结果
return result;
}
#pragma mark - 获取资源图片
//- (UIImage *)getPictureWithName:(NSString *)name{
// NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle bundleForClass:[self class]] pathForResource:@"CLPlayer" ofType:@"bundle"]];
// NSString *path = [bundle pathForResource:name ofType:@"png"];
// return [[UIImage imageWithContentsOfFile:path] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//}
@end
//
++ /dev/null
//
// UIView+IBExtension.h
// Weibo11
//
// Created by JYJ on 15/12/6.
// Copyright © 2015年 itheima. All rights reserved.
//
#import <UIKit/UIKit.h>
IB_DESIGNABLE
@interface UIView (IBExtension)
/// 边线颜色
@property (nonatomic, strong) IBInspectable UIColor *borderColor;
/// 边线宽度
@property (nonatomic, assign) IBInspectable CGFloat borderWidth;
/// 脚半径
@property (nonatomic, assign) IBInspectable CGFloat cornerRadius;
@end
//
++ /dev/null
//
// UIView+IBExtension.m
// Weibo11
//
// Created by JYJ on 15/12/6.
// Copyright © 2015年 itheima. All rights reserved.
//
#import "UIView+IBExtension.h"
@implementation UIView (IBExtension)
- (void)setBorderColor:(UIColor *)borderColor {
self.layer.borderColor = borderColor.CGColor;
}
- (UIColor *)borderColor {
return [UIColor colorWithCGColor:self.layer.borderColor];
}
- (void)setBorderWidth:(CGFloat)borderWidth {
self.layer.borderWidth = borderWidth;
}
- (CGFloat)borderWidth {
return self.layer.borderWidth;
}
- (void)setCornerRadius:(CGFloat)cornerRadius {
self.layer.cornerRadius = cornerRadius;
self.layer.masksToBounds = YES;
// 栅格化 - 提高性能
// 设置栅格化后,图层会被渲染成图片,并且缓存,再次使用时,不会重新渲染
self.layer.rasterizationScale = [UIScreen mainScreen].scale;
self.layer.shouldRasterize = YES;
}
- (CGFloat)cornerRadius {
return self.layer.cornerRadius;
}
@end
//
++ /dev/null
//
// UIView+bezierShape.h
// FeiPaiCustomer
//
// Created by honghong on 2017/9/19.
// Copyright © 2017年 cj. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIView (bezierShape)
/**
** lineView: 需要绘制成虚线的view
** lineLength: 虚线的宽度
** lineSpacing: 虚线的间距
** lineColor: 虚线的颜色
**/
+ (void)drawDashLine:(UIView *)lineView lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor;
/**
圆角
使用自动布局,需要在layoutsubviews 中使用
@param radius 圆角尺寸
@param corner 圆角位置
*/
- (void)drawRadiusWithRadius:(CGFloat)radius corner:(UIRectCorner)corner;
@end
//
++ /dev/null
//
// UIView+bezierShape.m
// FeiPaiCustomer
//
// Created by honghong on 2017/9/19.
// Copyright © 2017年 cj. All rights reserved.
//
#import "UIView+bezierShape.h"
@implementation UIView (bezierShape)
/**
** lineView: 需要绘制成虚线的view
** lineLength: 虚线的宽度
** lineSpacing: 虚线的间距
** lineColor: 虚线的颜色
**/
+ (void)drawDashLine:(UIView *)lineView lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor
{
NSLog(@"&&&&&&&&&&&&&&&& left is %@",NSStringFromCGRect(lineView.frame));
NSLog(@"width is %lf height is %lf",CGRectGetWidth(lineView.frame),CGRectGetHeight(lineView.frame));
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
[shapeLayer setBounds:lineView.bounds];
[shapeLayer setPosition:CGPointMake(CGRectGetWidth(lineView.frame) / 2, CGRectGetHeight(lineView.frame))];
[shapeLayer setFillColor:[UIColor clearColor].CGColor];
// 设置虚线颜色为blackColor
[shapeLayer setStrokeColor:lineColor.CGColor];
// 设置虚线宽度
[shapeLayer setLineWidth:CGRectGetHeight(lineView.frame)];
[shapeLayer setLineJoin:kCALineJoinRound];
// 设置线宽,线间距
[shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:lineLength], [NSNumber numberWithInt:lineSpacing], nil]];
// 设置路径
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 0, 0);
CGPathAddLineToPoint(path, NULL,CGRectGetWidth(lineView.frame), 0);
[shapeLayer setPath:path];
CGPathRelease(path);
// 把绘制好的虚线添加上来
[lineView.layer addSublayer:shapeLayer];
}
- (void)drawRadiusWithRadius:(CGFloat)radius corner:(UIRectCorner)corner{
UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = path.CGPath;
self.layer.mask = maskLayer;
}
@end
/*
++ /dev/null
/*
Erica Sadun, http://ericasadun.com
iPhone Developer's Cookbook, 3.0 Edition
BSD License, Use at your own risk
*/
#import <UIKit/UIKit.h>
CGPoint CGRectGetCenter(CGRect rect);
CGRect CGRectMoveToCenter(CGRect rect, CGPoint center);
@interface UIView (ViewFrameGeometry)
@property (nonatomic, assign) CGFloat x;
@property (nonatomic, assign) CGFloat y;
@property (nonatomic, assign) CGFloat width;
@property (nonatomic, assign) CGFloat height;
@property (nonatomic, assign) CGSize size;
@property (nonatomic, assign) CGFloat centerX;
@property (nonatomic, assign) CGFloat centerY;
@property CGPoint origin;
@property (readonly) CGPoint bottomLeft;
@property (readonly) CGPoint bottomRight;
@property (readonly) CGPoint topRight;
@property CGFloat top;
@property CGFloat left;
@property CGFloat bottom;
@property CGFloat right;
@property (nonatomic, assign) CGFloat middleX;
@property (nonatomic, assign) CGFloat middleY;
@property (nonatomic, assign) CGFloat tail;
+ (instancetype)viewFromXib;
//判断一个控件是否真正显示在主窗口
- (BOOL)isShowingOnKeyWindow;
- (void)reboundEffectAnimationDuration:(CGFloat)duration;
- (void) moveBy: (CGPoint) delta;
- (void) scaleBy: (CGFloat) scaleFactor;
- (void) fitInSize: (CGSize) aSize;
- (void)removeAllSubViews;
@end
/*
++ /dev/null
/*
Erica Sadun, http://ericasadun.com
iPhone Developer's Cookbook, 3.0 Edition
BSD License, Use at your own risk
*/
#import "UIViewExt.h"
#import "SDGeneralDefine.h"
CGPoint CGRectGetCenter(CGRect rect)
{
CGPoint pt;
pt.x = CGRectGetMidX(rect);
pt.y = CGRectGetMidY(rect);
return pt;
}
CGRect CGRectMoveToCenter(CGRect rect, CGPoint center)
{
CGRect newrect = CGRectZero;
newrect.origin.x = center.x-CGRectGetMidX(rect);
newrect.origin.y = center.y-CGRectGetMidY(rect);
newrect.size = rect.size;
return newrect;
}
@implementation UIView (ViewGeometry)
- (void)setX:(CGFloat)x
{
CGRect frame = self.frame;
frame.origin.x = x;
self.frame = frame;
}
- (CGFloat)x
{
return self.frame.origin.x;
}
- (void)setY:(CGFloat)y
{
CGRect frame = self.frame;
frame.origin.y = y;
self.frame = frame;
}
- (CGFloat)y
{
return self.frame.origin.y;
}
// Retrieve and set the origin
- (CGPoint) origin
{
return self.frame.origin;
}
- (void) setOrigin: (CGPoint) aPoint
{
CGRect newframe = self.frame;
newframe.origin = aPoint;
self.frame = newframe;
}
// Retrieve and set the size
- (CGSize) size
{
return self.frame.size;
}
- (void) setSize: (CGSize) aSize
{
CGRect newframe = self.frame;
newframe.size = aSize;
self.frame = newframe;
}
- (void)setCenterX:(CGFloat)centerX
{
CGPoint center = self.center;
center.x = centerX;
self.center = center;
}
- (CGFloat)centerX
{
return self.center.x;
}
- (void)setCenterY:(CGFloat)centerY
{
CGPoint center = self.center;
center.y = centerY;
self.center = center;
}
- (CGFloat)centerY
{
return self.center.y;
}
// Query other frame locations
- (CGPoint) bottomRight
{
CGFloat x = self.frame.origin.x + self.frame.size.width;
CGFloat y = self.frame.origin.y + self.frame.size.height;
return CGPointMake(x, y);
}
- (CGPoint) bottomLeft
{
CGFloat x = self.frame.origin.x;
CGFloat y = self.frame.origin.y + self.frame.size.height;
return CGPointMake(x, y);
}
- (CGPoint) topRight
{
CGFloat x = self.frame.origin.x + self.frame.size.width;
CGFloat y = self.frame.origin.y;
return CGPointMake(x, y);
}
// Retrieve and set height, width, top, bottom, left, right
- (CGFloat) height
{
return self.frame.size.height;
}
- (void) setHeight: (CGFloat) newheight
{
CGRect newframe = self.frame;
newframe.size.height = newheight;
self.frame = newframe;
}
- (CGFloat) width
{
return self.frame.size.width;
}
- (void) setWidth: (CGFloat) newwidth
{
CGRect newframe = self.frame;
newframe.size.width = newwidth;
self.frame = newframe;
}
- (CGFloat) top
{
return self.frame.origin.y;
}
- (void) setTop: (CGFloat) newtop
{
CGRect newframe = self.frame;
newframe.origin.y = newtop;
self.frame = newframe;
}
- (CGFloat) left
{
return self.frame.origin.x;
}
- (void) setLeft: (CGFloat) newleft
{
CGRect newframe = self.frame;
newframe.origin.x = newleft;
self.frame = newframe;
}
- (CGFloat) bottom
{
return self.frame.origin.y + self.frame.size.height;
}
- (void) setBottom: (CGFloat) newbottom
{
CGRect newframe = self.frame;
newframe.origin.y = newbottom - self.frame.size.height;
self.frame = newframe;
}
- (CGFloat) right
{
return self.frame.origin.x + self.frame.size.width;
}
- (void) setRight: (CGFloat) newright
{
CGFloat delta = newright - (self.frame.origin.x + self.frame.size.width);
CGRect newframe = self.frame;
newframe.origin.x += delta ;
self.frame = newframe;
}
// Move via offset
- (void) moveBy: (CGPoint) delta
{
CGPoint newcenter = self.center;
newcenter.x += delta.x;
newcenter.y += delta.y;
self.center = newcenter;
}
// Scaling
- (void) scaleBy: (CGFloat) scaleFactor
{
CGRect newframe = self.frame;
newframe.size.width *= scaleFactor;
newframe.size.height *= scaleFactor;
self.frame = newframe;
}
// Ensure that both dimensions fit within the given size by scaling down
- (void) fitInSize: (CGSize) aSize
{
CGFloat scale;
CGRect newframe = self.frame;
if (newframe.size.height && (newframe.size.height > aSize.height))
{
scale = aSize.height / newframe.size.height;
newframe.size.width *= scale;
newframe.size.height *= scale;
}
if (newframe.size.width && (newframe.size.width >= aSize.width))
{
scale = aSize.width / newframe.size.width;
newframe.size.width *= scale;
newframe.size.height *= scale;
}
self.frame = newframe;
}
- (void)setMiddleX:(CGFloat)middleX
{
CGRect frame = self.frame;
frame.origin.x = middleX - frame.size.width / 2;
self.frame = frame;
}
- (CGFloat)middleX
{
return CGRectGetMidX(self.frame);
}
- (void)setMiddleY:(CGFloat)middleY
{
CGRect frame = self.frame;
frame.origin.y = middleY - frame.size.height / 2 ;
self.frame = frame;
}
- (CGFloat)middleY
{
return CGRectGetMidY(self.frame);
}
- (CGFloat)tail
{
return CGRectGetMaxX(self.frame);
}
- (void)setTail:(CGFloat)tail
{
CGRect frame = self.frame;
frame.origin.x = tail - frame.size.width;
self.frame = frame;
}
- (void)removeAllSubViews
{
// for (int i = 0; i<self.subviews.count; i++) {
//
// }
for (UIView *view in self.subviews) {
[view removeFromSuperview];
}
}
+ (instancetype)viewFromXib
{
return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject];
}
- (BOOL)isShowingOnKeyWindow
{
// 主窗口
UIWindow *keyWindow = KKeyWindow;
// 以主窗口左上角为坐标原点, 计算self的矩形框
CGRect newFrame = [keyWindow convertRect:self.frame fromView:self.superview];
CGRect winBounds = keyWindow.bounds;
// 主窗口的bounds 和 self的矩形框 是否有重叠
BOOL intersects = CGRectIntersectsRect(newFrame, winBounds);
return !self.isHidden && self.alpha > 0.01 && self.window == keyWindow && intersects;
}
- (void)reboundEffectAnimationDuration:(CGFloat)duration
{ //缩放的动画 效果
CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.duration=duration;
animation.values = [NSArray arrayWithObjects:
[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.5, 0.5, 1.0)],
[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)],
[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 1.0)],
[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)],
nil];//x y z 放大缩小的倍数
[self.layer addAnimation:animation forKey:nil];
}
@end
//
++ /dev/null
//
// UIViewController+SDIphoneX.h
// OffcnLiveSDK
//
// Created by vockey on 2018/8/16.
// Copyright © 2018年 中公教育. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIViewController (SDIphoneX)
/**
状态栏加背景
*/
-(void)fixIphoneStatusBar;
/**
苹果X及以上手机适配底部安全区域加背景
*/
-(void)fixIphoneXBottom;
//是否含有刘海 即是否为X XS XS Max XR
-(BOOL)isHasFringe;
@end
//
++ /dev/null
//
// UIViewController+SDIphoneX.m
// OffcnLiveSDK
//
// Created by vockey on 2018/8/16.
// Copyright © 2018年 中公教育. All rights reserved.
//
#import "UIViewController+SDIphoneX.h"
#import "ZYJMasonry.h"
#import "UIViewExt.h"
#import "SDGeneralDefine.h"
@implementation UIViewController (SDIphoneX)
-(void)fixIphoneStatusBar{
UIView *statusBarBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, KStatusBarHeight)];
statusBarBackView.backgroundColor = [UIColor blackColor];
statusBarBackView.tag = 44;
[self.view addSubview:statusBarBackView];
[statusBarBackView mas_makeConstraints:^(ZYJMASConstraintMaker *make) {
make.top.leading.trailing.equalTo(self.view);
make.height.mas_equalTo(KStatusBarHeight);
}];
}
-(void)fixIphoneXBottom{
if (kIsIphoneX) {
UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.height - 34, kScreen_Width, 34)];
bottomView.backgroundColor = [UIColor whiteColor];
bottomView.tag = 34;
[self.view addSubview:bottomView];
[bottomView mas_makeConstraints:^(ZYJMASConstraintMaker *make) {
make.bottom.leading.trailing.equalTo(self.view);
make.height.mas_equalTo(34);
}];
}
}
//是否含有刘海 即是否为X XS XS Max XR
-(BOOL)isHasFringe{
CGFloat iPhoneNotchDirectionSafeAreaInsets = 0;
if (iOS11) {
UIEdgeInsets safeAreaInsets = [UIApplication sharedApplication].windows[0].safeAreaInsets;
switch ([UIApplication sharedApplication].statusBarOrientation) {
case UIInterfaceOrientationPortrait:{
iPhoneNotchDirectionSafeAreaInsets = safeAreaInsets.top;
}
break;
case UIInterfaceOrientationLandscapeLeft:{
iPhoneNotchDirectionSafeAreaInsets = safeAreaInsets.left;
}
break;
case UIInterfaceOrientationLandscapeRight:{
iPhoneNotchDirectionSafeAreaInsets = safeAreaInsets.right;
}
break;
case UIInterfaceOrientationPortraitUpsideDown:{
iPhoneNotchDirectionSafeAreaInsets = safeAreaInsets.bottom;
}
break;
default:
iPhoneNotchDirectionSafeAreaInsets = safeAreaInsets.top;
break;
}
return iPhoneNotchDirectionSafeAreaInsets > 20;
} else {
return NO;
}
}
@end
//
++ /dev/null
//
// DSToast.h
// DSToast
//
// Created by LS on 8/18/15.
// Copyright (c) 2015 LS. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, DSToastShowType)
{
DSToastShowTypeTop,
DSToastShowTypeCenter,
DSToastShowTypeBottom
};
@interface DSToast : UILabel
@property (nonatomic, assign) CFTimeInterval forwardAnimationDuration;
@property (nonatomic, assign) CFTimeInterval backwardAnimationDuration;
@property (nonatomic, assign) UIEdgeInsets textInsets;
@property (nonatomic, assign) CGFloat maxWidth;
@property (nonatomic, assign) DSToastShowType toastShowType;
+ (id)toastWithText:(NSString *)text;
- (id)initWithText:(NSString *)text;
- (void)showInView:(UIView *)view; //Default is DSToastShowTypeBottom
- (void)showInView:(UIView *)view showType:(DSToastShowType)type;
@end
//
++ /dev/null
//
// DSToast.m
// DSToast
//
// Created by LS on 8/18/15.
// Copyright (c) 2015 LS. All rights reserved.
//
#import "DSToast.h"
#import "SDGeneralDefine.h"
#import "UIViewExt.h"
@interface DSToast ()<CAAnimationDelegate>
@end
static CFTimeInterval const kDefaultForwardAnimationDuration = 0.5;
static CFTimeInterval const kDefaultBackwardAnimationDuration = 0.5;
static CFTimeInterval const kDefaultWaitAnimationDuration = 1.0;
static CGFloat const kDefaultTopMargin = 50.0;
static CGFloat const kDefaultBottomMargin = 50.0;
//static CGFloat const kDefalultTextInset = 10.0;
@implementation DSToast
+ (id)toastWithText:(NSString *)text
{
DSToast *toast = [[DSToast alloc] initWithText:text];
return toast;
}
- (id)initWithText:(NSString *)text
{
self = [self initWithFrame:CGRectZero];
if(self)
{
self.text = text;
[self sizeToFit];
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if(self)
{
self.forwardAnimationDuration = kDefaultForwardAnimationDuration;
self.backwardAnimationDuration = kDefaultBackwardAnimationDuration;
self.textInsets = UIEdgeInsetsMake(13.5, 44, 13.5, 44);
self.maxWidth = CGRectGetWidth([[UIScreen mainScreen] bounds]) - 20.0;
self.layer.cornerRadius = 6.0;
self.layer.masksToBounds = YES;
self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
self.numberOfLines = 0;
self.textAlignment = NSTextAlignmentLeft;
self.textColor = [UIColor whiteColor];
self.font = KFontNameMediumSize(13.0);
self.toastShowType = DSToastShowTypeCenter;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeRotate:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
}
return self;
}
- (void)changeRotate:(NSNotification*)noti{
[self endEditing:YES];
if (self.toastShowType == DSToastShowTypeCenter) {
self.center = KFirstWindow.center;
}else{
self.centerX = KFirstWindow.centerX;
self.centerY = KFirstWindow.centerY-100;
}
}
#pragma mark - Show Method
- (void)showInView:(UIView *)view
{
[self addAnimationGroup];
CGPoint point = view.center;
point.y = CGRectGetHeight(view.bounds)- kDefaultBottomMargin;
self.center = point;
for (int i=0; i<view.subviews.count; i++) {
if (i == view.subviews.count-1) {
if ([view.subviews[i] isKindOfClass:[DSToast class]]) {
[view.subviews[i] removeFromSuperview];
[view addSubview:self];
}else{
[view addSubview:self];
}
}else{
if ([view.subviews[i] isKindOfClass:[DSToast class]]) {
[view.subviews[i] removeFromSuperview];
}
}
}
}
- (void)showInView:(UIView *)view showType:(DSToastShowType)type
{
self.toastShowType = type;
[self addAnimationGroup];
CGPoint point = view.center;
switch (type) {
case DSToastShowTypeTop:
point.y = kDefaultTopMargin;
break;
case DSToastShowTypeBottom:
point.y = CGRectGetHeight(view.bounds)- kDefaultBottomMargin;
break;
default:
break;
}
self.center = point;
self.layer.cornerRadius = self.frame.size.height/2;
self.layer.masksToBounds = YES;
for (int i=0; i<view.subviews.count; i++) {
if (i == view.subviews.count-1) {
if ([view.subviews[i] isKindOfClass:[DSToast class]]) {
[view.subviews[i] removeFromSuperview];
[view addSubview:self];
}else{
[view addSubview:self];
}
}else{
if ([view.subviews[i] isKindOfClass:[DSToast class]]) {
[view.subviews[i] removeFromSuperview];
}
}
}
}
-(void)layoutSubviews{
[super layoutSubviews];
if (self.toastShowType == DSToastShowTypeCenter) {
self.center = KFirstWindow.center;
}else{
self.centerX = KFirstWindow.centerX;
self.centerY = KFirstWindow.centerY-100;
}
}
#pragma mark - Animation
- (void)addAnimationGroup
{
CABasicAnimation *forwardAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
forwardAnimation.duration = self.forwardAnimationDuration;
forwardAnimation.timingFunction = [CAMediaTimingFunction functionWithControlPoints:0.5f :1.7f :0.6f :0.85f];
forwardAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
forwardAnimation.toValue = [NSNumber numberWithFloat:1.0f];
CABasicAnimation *backwardAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
backwardAnimation.duration = self.backwardAnimationDuration;
backwardAnimation.beginTime = forwardAnimation.duration + kDefaultWaitAnimationDuration;
backwardAnimation.timingFunction = [CAMediaTimingFunction functionWithControlPoints:0.4f :0.15f :0.5f :-0.7f];
backwardAnimation.fromValue = [NSNumber numberWithFloat:1.0f];
backwardAnimation.toValue = [NSNumber numberWithFloat:0.0f];
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
animationGroup.animations = @[forwardAnimation,backwardAnimation];
animationGroup.duration = forwardAnimation.duration + backwardAnimation.duration + kDefaultWaitAnimationDuration;
animationGroup.removedOnCompletion = NO;
animationGroup.delegate = self;
animationGroup.fillMode = kCAFillModeForwards;
[self.layer addAnimation:animationGroup forKey:nil];
}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
if(flag)
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self removeFromSuperview];
}
}
- (void)setTextInsets:(UIEdgeInsets)textInsets{
CGRect frame = self.frame;
CGFloat width = CGRectGetWidth(self.bounds) + textInsets.left + textInsets.right;
frame.size.width = width > self.maxWidth? self.maxWidth : width;
frame.size.height = CGRectGetHeight(self.bounds) + textInsets.top + textInsets.bottom;
self.frame = frame;
self.textAlignment = NSTextAlignmentCenter;
}
#pragma mark - Text Configurate
- (void)sizeToFit
{
[super sizeToFit];
CGRect frame = self.frame;
CGFloat width = CGRectGetWidth(self.bounds) + self.textInsets.left + self.textInsets.right;
frame.size.width = width > self.maxWidth? self.maxWidth : width;
frame.size.height = CGRectGetHeight(self.bounds) + self.textInsets.top + self.textInsets.bottom;
self.frame = frame;
}
- (void)drawTextInRect:(CGRect)rect
{
[super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.textInsets)];
}
- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines
{
bounds.size = [self.text boundingRectWithSize:CGSizeMake(self.maxWidth - self.textInsets.left - self.textInsets.right,
CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:self.font} context:nil].size;
return bounds;
}
@end
//
++ /dev/null
//
// OffcnToast.h
// OffcnIMSDKiOS
//
// Created by vockey on 2019/4/9.
// Copyright © 2019年 中公教育. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "DSToast.h"
@interface OffcnToast : NSObject
/**
Toast提示
@param titlemessage 提示内容
*/
+(void)toastWithTitlemessage:(NSString *)titlemessage;
/**
Toast提示
@param titlemessage 提示内容
@param type 位置
*/
+(void)toastWithTitlemessage:(NSString *)titlemessage showType:(DSToastShowType)type;
@end
//
++ /dev/null
//
// OffcnToast.m
// OffcnIMSDKiOS
//
// Created by vockey on 2019/4/9.
// Copyright © 2019年 中公教育. All rights reserved.
//
#import "OffcnToast.h"
#import "DSToast.h"
#import "SDGeneralDefine.h"
@implementation OffcnToast
//toast
+(void)toastWithTitlemessage:(NSString *)titlemessage{
if(titlemessage.length>0){
DSToast *toast = [[DSToast alloc] initWithText:titlemessage];
toast.maxWidth = 284.0;
toast.textInsets = UIEdgeInsetsMake(13.5, 44, 13.5, 44);
[toast showInView:KKeyWindow showType:DSToastShowTypeCenter];
}
}
+(void)toastWithTitlemessage:(NSString *)titlemessage showType:(DSToastShowType)type{
if(titlemessage.length>0){
DSToast *toast = [[DSToast alloc] initWithText:titlemessage];
toast.maxWidth = 284.0;
toast.textInsets = UIEdgeInsetsMake(13.5, 44, 13.5, 44);
[toast showInView:KKeyWindow showType:type];
}
}
@end
//
++ /dev/null
//
// SDGeneralTool.h
// HomeHealth
//
// Created by newuser on 16/12/30.
// Copyright © 2016年 ChiJian. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "OffcnBaseNetworking.h"
@interface SDGeneralTool : NSObject
//toast
+(void)toastWithTitlemessage:(NSString *)titlemessage;
+(void)removeDSToast;
//Alert弹框
+(void)popAlertControllerWithTarget:(UIViewController *)target title:(NSString *)title message:(NSString *)message finished:(void(^)(UIAlertAction * _Nonnull action))finished;
//push
+(void)pushViewControllerWithController:(UIViewController *)Controller;
+ (NSString*)deviceVersion;
+ (NSString *)getDouble2Num:(id)num;
#pragma mark - 计算时间差
+(BOOL)isPassMinute:(int)min startTime:(NSString *)startTime endTime:(NSString *)endTime;
//聊天获取下一条消息时间标签
+(NSString*)getNextMsgTimeWithTime:(NSString *)Time;
//当天时间
+(NSString*)getHistorySameDayTimeWithTime:(NSString *)Time;
//获取当前的时间
+(NSString*)getCurrentTimes;
+(NSString*)getAllCurrentTimes;
//获取当前时间戳(以毫秒为单位)
+(NSString *)getNowTimeTimestampMillisecond;
//获取当前时间戳(以秒为单位)
+(NSString *)getNowSSTimeTimestamp;
//获取当前时间戳(以毫秒为单位)
+(NSString *)getNowSSSTimeTimestamp;
+(NSString *)getHHTimeWithSeconds:(NSTimeInterval)s;
+(NSString *)getIMAllTimeWithSeconds:(NSTimeInterval)s;
+ (NSString *)getTimeWithSeconds:(NSTimeInterval)s;
+(NSString *)getTimeWithDate:(NSDate *)date;
+ (BOOL)isAllowInputPasssword:(NSString *)str;
//[6-20位字符,可由中文、英文、数字及“_”、“-”组成]
+(BOOL)isValidateName:(NSString *)name;
//手机号验证
+(BOOL)checkTelNumber:(NSString *)telNumber;
+ (BOOL)isIPhoneX;
+ (BOOL)isIPhone4;
//base64编码
+(NSString *)encode:(NSString *)string;
//base64解码
+(NSString *)dencode:(NSString *)base64String;
//获取系统开机时间到1970时间差值
+(double)getLaunchSystemTime;
//将某个时间转化成时间戳
+(NSInteger)timeSwitchTimestamp:(NSString *)formatTime;
+(NSInteger)timeSwitchDayTimestamp:(NSString *)formatTime;
//GMT格式---@"d MMM yyyy HH:mm:ss 'GMT'"
+(NSString *)getGMTTimestamp;
//隐藏手机号
+(NSString *)hidNameWithStr:(NSString *)str;
//普通字符串转换为十六进制的
+(NSString *)hexStringFromString:(NSString *)string;
@end
//
++ /dev/null
//
// CJLoadingView.h
// FeiPaiCustomer
//
// Created by newuser on 2017/9/26.
// Copyright © 2017年 cj. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface CJLoadingView : UIView
-(void)startAnimation;
-(void)stopAnimation;
@end
//
++ /dev/null
//
// CJLoadingView.m
// FeiPaiCustomer
//
// Created by newuser on 2017/9/26.
// Copyright © 2017年 cj. All rights reserved.
//
#import "CJLoadingView.h"
#import "UIViewExt.h"
@interface CJLoadingView()
@property (nonatomic, strong)UIImageView* loadingImageView;
@end
@implementation CJLoadingView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self uiConfig];
}
return self;
}
-(void)uiConfig{
// self.loadingImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 8, 5.5)];
self.loadingImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 21.5, 14)];
self.loadingImageView.center = CGPointMake(self.width/2, self.height/2 - 10);
[self addSubview:self.loadingImageView];
NSMutableArray *imgArray = [NSMutableArray array];
for (int i=1; i<=8; i++) {
// UIImage *image = KImageNamed([NSString stringWithFormat:@"loading_%i",i]);
// [imgArray addObject:image];
}
self.loadingImageView.animationImages = imgArray;
self.loadingImageView.animationDuration = 0.8;
self.loadingImageView.animationRepeatCount = MAXFLOAT;
}
-(void)startAnimation{
self.loadingImageView.center = CGPointMake(self.width/2, self.height/2 - 10);
[self.loadingImageView startAnimating];
}
-(void)stopAnimation{
[self.loadingImageView stopAnimating];
}
@end
//
++ /dev/null
//
// SDTool.h
// HomeHealth
//
// Created by newuser on 17/1/4.
// Copyright © 2017年 ChiJian. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface SDTool : NSObject
+(instancetype)instance;
+ (void)showHUDWithText:(NSString *)text;
+ (void)showHUDCustomSucceesWithText:(NSString *)text;
+ (void)showHUDWithText:(NSString *)text callback:(void(^)(void))callback;
+ (void)showHUDWithTextAndNotNoMessage:(NSString *)text;
//菊花
+(void)showLoadingOnView:(UIView *)view;
//主要是为了解决在找不到vc.view的时候方便使用
+(void)showLoadingOnWindowCustomFrame:(CGRect)frame;
+(void)showLoadingOnWindow;
+(void)hideLoading;
//本地打电话
+ (void)callPhone:(NSString *)phoneNum;
//判断网络状态
+ (BOOL)isExistenceNetwork;
//设置状态栏颜色
//+ (void)setStatusBarBackgroundColor:(UIColor *)color;
@end
//
++ /dev/null
//
// SDTool.m
// HomeHealth
//
// Created by newuser on 17/1/4.
// Copyright © 2017年 ChiJian. All rights reserved.
//
#import "SDTool.h"
#import "CJLoadingView.h"
#import "ZYJRealReachability.h"
#import "ZYJMBProgressHUD.h"
#import "SDGeneralDefine.h"
@interface SDTool ()
@property (strong,nonatomic)UIActivityIndicatorView *indicatorView;
@property (strong,nonatomic)CJLoadingView *loadingView;
@end
@implementation SDTool
+(instancetype)instance{
static SDTool *tl = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
tl = [[SDTool alloc]init];
});
return tl;
}
-(UIActivityIndicatorView *)indicatorView{
if (!_indicatorView) {
_indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
_indicatorView.frame = KKeyWindow.bounds;
}
return _indicatorView;
}
-(CJLoadingView *)loadingView{
if (!_loadingView) {
_loadingView = [[CJLoadingView alloc] initWithFrame:KKeyWindow.bounds];
}
return _loadingView;
}
+ (void)showHUDWithText:(NSString *)text
{
if ([text length]<=0) {
return;
}
[SDTool showWarning:KKeyWindow mText:text seconds:2.0 callback:nil];
}
+ (void)showHUDWithText:(NSString *)text callback:(void(^)(void))callback
{
[SDTool showWarning:KKeyWindow mText:text seconds:2.0 callback:callback];
}
+ (void)showHUDWithTextAndNotNoMessage:(NSString *)text{
if (text && [text respondsToSelector:@selector(length)] &&text.length && ![text isEqualToString:@"请求失败"]) {
[SDTool showHUDWithText:text];
}
}
+(void)showWarning:(UIView *)view mText:(NSString *)text seconds:(CGFloat)seconds callback:(void(^)(void))hudCallBack{
ZYJMBProgressHUD *hud = [ZYJMBProgressHUD showHUDAddedTo:view animated:YES];
NSMutableParagraphStyle *pStyle = [[NSMutableParagraphStyle alloc]init];
[pStyle setLineSpacing:0.5];
[pStyle setLineBreakMode:NSLineBreakByWordWrapping];
CGRect matchRect = [text boundingRectWithSize:CGSizeMake(190, 150) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:KFontNameMediumSize(13),NSFontAttributeName,pStyle,NSParagraphStyleAttributeName, nil] context:nil];
hud.mode = ZYJMBProgressHUDModeCustomView;
UILabel *mLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, matchRect.size.width, matchRect.size.height)];
mLabel.backgroundColor = [UIColor clearColor];
mLabel.textColor = [UIColor whiteColor];
mLabel.font = KFontNameMediumSize(13);
mLabel.textAlignment = NSTextAlignmentCenter;
mLabel.lineBreakMode = NSLineBreakByWordWrapping;
mLabel.numberOfLines = 0;
mLabel.text = text;
hud.customView = mLabel;
hud.bezelView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
if (hudCallBack) {
hud.completionBlock = [hudCallBack copy];
}
[hud hideAnimated:YES afterDelay:seconds];
}
+ (void)showHUDCustomSucceesWithText:(NSString *)text
{
if ([text length]<=0) {
return;
}
[SDTool showCustomSuccees:KKeyWindow mText:text seconds:2.0 callback:nil];
}
+(void)showCustomSuccees:(UIView *)view mText:(NSString *)text seconds:(CGFloat)seconds callback:(void(^)(void))hudCallBack{
ZYJMBProgressHUD *hud = [ZYJMBProgressHUD showHUDAddedTo:view animated:YES];
hud.mode = ZYJMBProgressHUDModeCustomView;
hud.customView = [[UIImageView alloc] initWithImage:KImageNamed(@"SDVideo_tiJiaoChengGong")];
hud.label.text = text;
hud.label.textColor = [UIColor whiteColor];
hud.label.font = KFontNameMediumSize(13);
hud.bezelView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
if (hudCallBack) {
hud.completionBlock = [hudCallBack copy];
}
[hud hideAnimated:YES afterDelay:seconds];
}
+(void)showLoadingOnView:(UIView *)view{
[SDTool instance].indicatorView.frame = view.bounds;
[view addSubview:[SDTool instance].indicatorView];
[[SDTool instance].indicatorView startAnimating];
// [SDTool instance].loadingView.frame = view.bounds;
// [view addSubview:[SDTool instance].loadingView];
// [[SDTool instance].loadingView startAnimation];
}
+(void)showLoadingOnWindowCustomFrame:(CGRect)frame{
[SDTool instance].indicatorView.frame = frame;
[KKeyWindow addSubview:[SDTool instance].indicatorView];
[[SDTool instance].indicatorView startAnimating];
// [SDTool instance].loadingView.frame = frame;
// [KKeyWindow addSubview:[SDTool instance].loadingView];
// [[SDTool instance].loadingView startAnimation];
}
+(void)showLoadingOnWindow{
[SDTool instance].indicatorView.frame = [UIScreen mainScreen].bounds;
[KKeyWindow addSubview:[SDTool instance].indicatorView];
[[SDTool instance].indicatorView startAnimating];
// [SDTool instance].loadingView.frame = [UIScreen mainScreen].bounds;
// [KKeyWindow addSubview:[SDTool instance].loadingView];
// [[SDTool instance].loadingView startAnimation];
}
+(void)hideLoading{
[[SDTool instance].indicatorView stopAnimating];
[[SDTool instance].indicatorView removeFromSuperview];
// [[SDTool instance].loadingView removeFromSuperview];
// [[SDTool instance].loadingView stopAnimation];
}
+ (void)callPhone:(NSString *)phoneNum{
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:phoneNum message:@"" delegate:[SDTool instance] cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
alertView.tag = 10086;
[alertView show];
// NSMutableString* str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",phoneNum];
// // NSLog(@"str======%@",str);
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1 && alertView.tag == 10086) {
NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",alertView.title]];
[[UIApplication sharedApplication] openURL:phoneURL];
}
}
+ (BOOL)isExistenceNetwork
{
BOOL isExistenceNetwork = false;
ReachabilityStatus status = [GLobalRealReachability currentReachabilityStatus];
NSLog(@"Initial reachability status:%@",@(status));
if (status == RealStatusNotReachable)
{
isExistenceNetwork = false;
}
if (status == RealStatusViaWiFi)
{
isExistenceNetwork = true;
}
if (status == RealStatusViaWWAN)
{
isExistenceNetwork = true;
}
return isExistenceNetwork;
}
//设置状态栏颜色
//+ (void)setStatusBarBackgroundColor:(UIColor *)color{
// [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
// UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
// if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
// statusBar.backgroundColor = color;
// }
//}
@end
//
++ /dev/null
//
// OffcnBaseNetworking.h
// OffcnIMSDKiOS
//
// Created by vockey on 2018/7/25.
// Copyright © 2018年 中公教育. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ZYJAFNetworking.h"
@class BaseResponse;
//token 失效的code
//static NSInteger const KtokenCode = 401;
//无网的code(此code为自定义)
static NSInteger const KNoNetWorkCode = 20170109;
typedef void(^NetworkCallBack)(BaseResponse * baseResponse);
@interface OffcnBaseNetworking : NSObject
@property(strong, nonatomic) ZYJAFHTTPSessionManager *manager;
//需要对接传入参数serviceType;httpHeaderDic
/// 设置默认服务器 1为开发服务器, 2为测试服务器, 3为正式服务器
@property (nonatomic , assign)NSInteger serviceType;
//登陆后获取的token
@property (nonatomic , copy)NSString *token;
@property (nonatomic , copy)NSString *imageBaseUrl;
@property (nonatomic , strong)NSDictionary *httpHeaderDic;
+ (instancetype)sharedInstance;
+ (void)configureHttpHeaderWithDict:(NSDictionary *)dict;
+(NSString *)get_BASEURL;
//图片服务器
+(NSString *)get_ImageBaseUrl;
//h5服务器
+(NSString *)get_h5live;
//call_server_topic服务器
+(NSString *)get_call_server_topic;
+ (void)getFromURL:(NSString *)URLString
params:(NSDictionary *)params
finished:(NetworkCallBack)finished;
+ (void)postToURL:(NSString *)URLString
bodyParams:(id)bodyParams
finished:(NetworkCallBack)finished;
+ (void)putToURL:(NSString *)URLString
bodyParams:(id)bodyParams
finished:(NetworkCallBack)finished;
+ (void)deleteToURL:(NSString *)URLString
bodyParams:(id)bodyParams
finished:(NetworkCallBack)finished;
/**
* 取消去全部
*/
- (void)cancelAllOperations;
//上传图片
//+ (void)getImgurl:(NSString *)url imgArr:(NSMutableArray *)imgArr index:(NSInteger)index finished:(NetworkCallBack)finished;
@end
@interface BaseResponse : NSObject
///返回的httpCode
@property (assign,nonatomic) NSInteger httpCode;
@property (assign,nonatomic) NSInteger code;
///返回的错误信息
@property (copy,nonatomic) NSString *errorMessage;
///是否成功
@property (assign) BOOL isSuccess;
@property(copy, nonatomic) NSString *url;//请求url
@property (nonatomic) id responseObject;
@property (nonatomic,strong) NSError *error;
@property (nonatomic, strong) NSURLSessionDataTask *task;
- (instancetype)initWithTask:(NSURLSessionDataTask *)task responseObject :(id)responseObject error :(NSError *) error;
-(BaseResponse *)checkNotReachability;
@end
//
++ /dev/null
//
// OffcnNetworkExecutor.h
// OffcnIMSDKiOS
//
// Created by vockey on 2018/7/25.
// Copyright © 2018年 中公教育. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "OffcnBaseNetworking.h"
#import "OffcnIMModel.h"
@interface OffcnNetworkExecutor : NSObject
+ (void)cancelAllOperations;
//sendAsynchronousRequest
+ (void)requesImgJsonWithUrlStr:(NSString *)urlStr Finished:(void(^)(BOOL success,id response,NSString *message))finished;
//发送消息
+ (void)requestSendMsgWithMsg_fromID:(NSString *)msg_fromID msg_toID:(NSString *)msg_toID msg_type:(NSInteger)msg_type tid:(NSString *)tid msg:(NSMutableDictionary *)msgDic Finished:(void(^)(BOOL success,OffcnIMSendMsgModel *sendMsgModel,BaseResponse *baseResponse))finished;
//用户信息标记已读
+ (void)requestMarkMsgReadWithMsg_fromID:(NSString *)msg_fromID msg_toID:(NSString *)msg_toID msg_seq:(NSInteger)msg_seq Finished:(void(^)(BOOL success,id response,BaseResponse *baseResponse))finished;
//获取会话未读消息列表
+ (void)requestGetSessionUnreadMsgWithFromID:(NSString *)fromID toID:(NSString *)toID Finished:(void(^)(BOOL success,OffcnIMUnreadMsgModel *unreadMsgModel,BaseResponse *baseResponse))finished;
//获取用户最近会话记录
+ (void)requestGetRecentSessionsWithAccid:(NSString *)accid Finished:(void(^)(BOOL success,OffcnIMRecentMsgModel *recentMsgModel,BaseResponse *baseResponse))finished;
//获取会话历史消息列表
+ (void)requestGetSessionHistoryMsgWithFromID:(NSString *)fromID toID:(NSString *)toID msg_seq:(NSString *)msg_seq Finished:(void(^)(BOOL success,OffcnIMHistoryMsgModel *historyMsgModel,BaseResponse *baseResponse))finished;
//获取七牛Token
+ (void)requestUploadTokenFinished:(void(^)(BOOL success,id response,BaseResponse *baseResponse))finished;
//注册用户设备
+ (void)requestRegisterDevicesWithAccid:(NSString *)accid device_token:(NSString *)device_token Finished:(void(^)(BOOL success,id response,BaseResponse *baseResponse))finished;
//注销用户设备
+ (void)requestUnregisterDevicesWithAccid:(NSString *)accid device_token:(NSString *)device_token Finished:(void(^)(BOOL success,id response,BaseResponse *baseResponse))finished;
@end
This diff is collapsed. Click to expand it.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment