EZDemo/HDLEZDemo/HDLEZDemo/Assets.xcassets/hdl_ez_cat_eyes_answer.imageset/Contents.json
New file @@ -0,0 +1,22 @@ { "images" : [ { "idiom" : "universal", "scale" : "1x" }, { "filename" : "hdl_ez_cat_eyes_answer@2x.png", "idiom" : "universal", "scale" : "2x" }, { "filename" : "hdl_ez_cat_eyes_answer@3x.png", "idiom" : "universal", "scale" : "3x" } ], "info" : { "author" : "xcode", "version" : 1 } } EZDemo/HDLEZDemo/HDLEZDemo/Assets.xcassets/hdl_ez_cat_eyes_answer.imageset/hdl_ez_cat_eyes_answer@2x.png
EZDemo/HDLEZDemo/HDLEZDemo/Assets.xcassets/hdl_ez_cat_eyes_answer.imageset/hdl_ez_cat_eyes_answer@3x.png
EZDemo/HDLEZDemo/HDLEZDemo/Assets.xcassets/hdl_ez_cat_eyes_hang_up.imageset/Contents.json
New file @@ -0,0 +1,22 @@ { "images" : [ { "idiom" : "universal", "scale" : "1x" }, { "filename" : "hdl_ez_cat_eyes_hang_up@2x.png", "idiom" : "universal", "scale" : "2x" }, { "filename" : "hdl_ez_cat_eyes_hang_up@3x.png", "idiom" : "universal", "scale" : "3x" } ], "info" : { "author" : "xcode", "version" : 1 } } EZDemo/HDLEZDemo/HDLEZDemo/Assets.xcassets/hdl_ez_cat_eyes_hang_up.imageset/hdl_ez_cat_eyes_hang_up@2x.png
EZDemo/HDLEZDemo/HDLEZDemo/Assets.xcassets/hdl_ez_cat_eyes_hang_up.imageset/hdl_ez_cat_eyes_hang_up@3x.png
EZDemo/HDLEZDemo/HDLEZDemo/Assets.xcassets/hdl_ez_cat_eyes_ignore.imageset/Contents.json
New file @@ -0,0 +1,22 @@ { "images" : [ { "idiom" : "universal", "scale" : "1x" }, { "filename" : "hdl_ez_cat_eyes_ignore@2x.png", "idiom" : "universal", "scale" : "2x" }, { "filename" : "hdl_ez_cat_eyes_ignore@3x.png", "idiom" : "universal", "scale" : "3x" } ], "info" : { "author" : "xcode", "version" : 1 } } EZDemo/HDLEZDemo/HDLEZDemo/Assets.xcassets/hdl_ez_cat_eyes_ignore.imageset/hdl_ez_cat_eyes_ignore@2x.png
EZDemo/HDLEZDemo/HDLEZDemo/Assets.xcassets/hdl_ez_cat_eyes_ignore.imageset/hdl_ez_cat_eyes_ignore@3x.png
EZDemo/HDLEZDemo/HDLEZDemo/EZMain.storyboard
@@ -1293,70 +1293,46 @@ <rect key="frame" x="0.0" y="312" width="375" height="355"/> <subviews> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="---" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8Fe-E7-C5g"> <rect key="frame" x="32" y="89" width="311" height="21"/> <rect key="frame" x="32" y="46.5" width="311" height="21"/> <fontDescription key="fontDescription" type="system" pointSize="17"/> <color key="textColor" red="0.090196078430000007" green="0.094117647060000004" blue="0.29411764709999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <nil key="highlightedColor"/> </label> <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="aq5-rn-Dgo"> <rect key="frame" x="142.5" y="160" width="84.5" height="35"/> <button opaque="NO" contentMode="scaleAspectFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="aq5-rn-Dgo" customClass="HDLEZOPButton"> <rect key="frame" x="142.5" y="117.5" width="84.5" height="120"/> <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <state key="normal" title="Button"/> <buttonConfiguration key="configuration" style="plain" title="忽略"/> <userDefinedRuntimeAttributes> <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius"> <integer key="value" value="8"/> </userDefinedRuntimeAttribute> <userDefinedRuntimeAttribute type="boolean" keyPath="layer.masksToBounds" value="YES"/> <userDefinedRuntimeAttribute type="number" keyPath="layer.borderWidth"> <real key="value" value="0.5"/> </userDefinedRuntimeAttribute> <userDefinedRuntimeAttribute type="color" keyPath="layer. borderColorWithUIColor"> <color key="value" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> </userDefinedRuntimeAttribute> </userDefinedRuntimeAttributes> <fontDescription key="fontDescription" type="system" pointSize="14"/> <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/> <state key="normal" title="忽略" image="hdl_ez_cat_eyes_ignore"> <color key="titleColor" red="0.10588235294117647" green="0.1764705882352941" blue="0.30196078431372547" alpha="1" colorSpace="calibratedRGB"/> </state> <connections> <action selector="clickCalloutIgnoreAction:" destination="uBF-Yq-Qo0" eventType="touchUpInside" id="fTQ-p0-9jk"/> </connections> </button> <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="2bC-B5-gMZ"> <rect key="frame" x="259" y="160" width="84" height="35"/> <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="2bC-B5-gMZ" customClass="HDLEZOPButton"> <rect key="frame" x="259" y="117.5" width="84" height="120"/> <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <state key="normal" title="Button"/> <buttonConfiguration key="configuration" style="plain" title="接听"/> <userDefinedRuntimeAttributes> <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius"> <integer key="value" value="8"/> </userDefinedRuntimeAttribute> <userDefinedRuntimeAttribute type="boolean" keyPath="layer.masksToBounds" value="YES"/> <userDefinedRuntimeAttribute type="number" keyPath="layer.borderWidth"> <real key="value" value="0.5"/> </userDefinedRuntimeAttribute> <userDefinedRuntimeAttribute type="color" keyPath="layer. borderColorWithUIColor"> <color key="value" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> </userDefinedRuntimeAttribute> </userDefinedRuntimeAttributes> <fontDescription key="fontDescription" type="system" pointSize="14"/> <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/> <state key="normal" title="接听" image="hdl_ez_cat_eyes_answer"> <color key="titleColor" red="0.10588235294117647" green="0.1764705882352941" blue="0.30196078431372547" alpha="1" colorSpace="calibratedRGB"/> </state> <connections> <action selector="clickCalloutAnswerAction:" destination="uBF-Yq-Qo0" eventType="touchUpInside" id="2tR-65-1sv"/> </connections> </button> <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="jPI-nC-uAq"> <rect key="frame" x="32" y="160" width="78.5" height="35"/> <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="jPI-nC-uAq" customClass="HDLEZOPButton"> <rect key="frame" x="32" y="117.5" width="78.5" height="120"/> <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <state key="normal" title="Button"/> <buttonConfiguration key="configuration" style="plain" title="挂断"/> <userDefinedRuntimeAttributes> <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius"> <integer key="value" value="8"/> </userDefinedRuntimeAttribute> <userDefinedRuntimeAttribute type="boolean" keyPath="layer.masksToBounds" value="YES"/> <userDefinedRuntimeAttribute type="number" keyPath="layer.borderWidth"> <real key="value" value="0.5"/> </userDefinedRuntimeAttribute> <userDefinedRuntimeAttribute type="color" keyPath="layer. borderColorWithUIColor"> <color key="value" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> </userDefinedRuntimeAttribute> </userDefinedRuntimeAttributes> <constraints> <constraint firstAttribute="height" constant="120" id="NXb-C0-Nw5"/> </constraints> <fontDescription key="fontDescription" type="system" pointSize="14"/> <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/> <state key="normal" title="挂断" image="hdl_ez_cat_eyes_hang_up"> <color key="titleColor" red="0.1058823529" green="0.1764705882" blue="0.30196078430000001" alpha="1" colorSpace="calibratedRGB"/> </state> <connections> <action selector="clickCalloutHangupAction:" destination="uBF-Yq-Qo0" eventType="touchUpInside" id="Szo-xH-Mh6"/> </connections> @@ -1368,7 +1344,6 @@ <constraint firstAttribute="trailing" secondItem="8Fe-E7-C5g" secondAttribute="trailing" constant="32" id="8NR-Fc-tPc"/> <constraint firstItem="aq5-rn-Dgo" firstAttribute="leading" secondItem="jPI-nC-uAq" secondAttribute="trailing" constant="32" id="8ht-5u-0y7"/> <constraint firstItem="2bC-B5-gMZ" firstAttribute="height" secondItem="aq5-rn-Dgo" secondAttribute="height" id="B0O-2O-7OG"/> <constraint firstAttribute="height" secondItem="aq5-rn-Dgo" secondAttribute="height" multiplier="10.1429" id="BR6-y6-ljY"/> <constraint firstItem="jPI-nC-uAq" firstAttribute="centerY" secondItem="sMv-Yh-W5N" secondAttribute="centerY" id="Fa3-MI-9zW"/> <constraint firstItem="aq5-rn-Dgo" firstAttribute="width" secondItem="jPI-nC-uAq" secondAttribute="width" multiplier="1.07143" id="Jzm-Kq-s1B"/> <constraint firstItem="aq5-rn-Dgo" firstAttribute="top" secondItem="8Fe-E7-C5g" secondAttribute="bottom" constant="50" id="aM7-YH-wta"/> @@ -2602,6 +2577,9 @@ <image name="chuanshujilu--2" width="24" height="24"/> <image name="cloud" width="32" height="32"/> <image name="duijiangji" width="39" height="39"/> <image name="hdl_ez_cat_eyes_answer" width="68" height="68"/> <image name="hdl_ez_cat_eyes_hang_up" width="68" height="68"/> <image name="hdl_ez_cat_eyes_ignore" width="68" height="68"/> <image name="hdl_ez_list_next" width="8" height="8"/> <image name="icon_download_fill" width="20" height="20"/> <image name="large_back_btn" width="10" height="19"/> EZDemo/HDLEZDemo/HDLEZDemo/libEZSDK.aBinary files differ
EZDemo/HDLEZDemo/HDLEZDemo/resources/en.lproj/Localizable.strings
@@ -50,6 +50,7 @@ "device_verify_code_wrong"="Incorrect device password."; "device_restart_talk"="Enabling two-way audio. Please wait..."; "device_save_gallery"="Saved to the albums."; "device_save_gallery_failure"="Download failure"; "device_analogue_camera"="Analog Channel"; "device_digital_camera"="Digital Channel"; "device_lan_device_list_title"="LAN Device List"; EZDemo/HDLEZDemo/HDLEZDemo/resources/zh-Hans.lproj/Localizable.strings
@@ -50,6 +50,7 @@ "device_verify_code_wrong"="设备密码错误"; "device_restart_talk"="正在开启对讲,请稍候..."; "device_save_gallery"="已保存至手机相册"; "device_save_gallery_failure"="下载失败"; "device_analogue_camera"="模拟通道"; "device_digital_camera"="数字通道"; "device_lan_device_list_title"="局域网设备列表"; EZSDK/EZSDK.xcodeproj/project.pbxproj
@@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 830957C32A3AE3E1002B68AA /* HDLEZVideoDoorMsgCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 830957C22A3AE3E1002B68AA /* HDLEZVideoDoorMsgCell.m */; }; 83EE503D2A41C9BA0006435D /* HDLEZOPButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 83EE503C2A41C9BA0006435D /* HDLEZOPButton.m */; }; AE31FE1F29CC2D2200678568 /* EZOpenSDKFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AE31FE1E29CC2D2200678568 /* EZOpenSDKFramework.framework */; platformFilter = ios; }; AE5068D829B9DB5E009EA09A /* HDLEZTemInfoModel.m in Sources */ = {isa = PBXBuildFile; fileRef = AE5068D729B9DB5E009EA09A /* HDLEZTemInfoModel.m */; }; AEC306D229B9F2B5000B3861 /* HDLEZVisitorRecordView.m in Sources */ = {isa = PBXBuildFile; fileRef = AEC306D129B9F2B5000B3861 /* HDLEZVisitorRecordView.m */; }; @@ -187,6 +188,8 @@ /* Begin PBXFileReference section */ 830957C12A3AE3E1002B68AA /* HDLEZVideoDoorMsgCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HDLEZVideoDoorMsgCell.h; sourceTree = "<group>"; }; 830957C22A3AE3E1002B68AA /* HDLEZVideoDoorMsgCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HDLEZVideoDoorMsgCell.m; sourceTree = "<group>"; }; 83EE503B2A41C9BA0006435D /* HDLEZOPButton.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HDLEZOPButton.h; sourceTree = "<group>"; }; 83EE503C2A41C9BA0006435D /* HDLEZOPButton.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HDLEZOPButton.m; sourceTree = "<group>"; }; AE31FE1E29CC2D2200678568 /* EZOpenSDKFramework.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = EZOpenSDKFramework.framework; sourceTree = "<group>"; }; AE5068D629B9DB5E009EA09A /* HDLEZTemInfoModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HDLEZTemInfoModel.h; sourceTree = "<group>"; }; AE5068D729B9DB5E009EA09A /* HDLEZTemInfoModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HDLEZTemInfoModel.m; sourceTree = "<group>"; }; @@ -690,6 +693,8 @@ AEF0148E29C188ED00D014FD /* HDLEZScrollView.m */, AEDD437E29BED161001D9477 /* HDLEZButton.h */, AEDD437D29BED161001D9477 /* HDLEZButton.m */, 83EE503B2A41C9BA0006435D /* HDLEZOPButton.h */, 83EE503C2A41C9BA0006435D /* HDLEZOPButton.m */, AEE84D4729BAE2550078FDAD /* HDLEZNoDataView.h */, AEE84D4829BAE2590078FDAD /* HDLEZNoDataView.m */, AEE84D4529BACBAD0078FDAD /* HDLEZTopBarView.h */, @@ -1574,6 +1579,7 @@ B9BC9A1E25C0FFBD00C024FE /* EZWifiInfoViewController.m in Sources */, 830957C32A3AE3E1002B68AA /* HDLEZVideoDoorMsgCell.m in Sources */, AEF0148F29C188ED00D014FD /* HDLEZScrollView.m in Sources */, 83EE503D2A41C9BA0006435D /* HDLEZOPButton.m in Sources */, B9BC9A1925C0FFBD00C024FE /* EZAPWiFiConfigViewController.m in Sources */, B95AB88826984DD5007BC8D7 /* YYClassInfo.m in Sources */, B95AB88726984DD5007BC8D7 /* NSObject+YYModel.m in Sources */, EZSDK/EZSDK/EZ/Base/HDLEZOPButton.h
New file @@ -0,0 +1,88 @@ // // HDLEZOPButton.h // EZSDK // // Created by Davin on 2023/6/20. // #import <UIKit/UIKit.h> NS_ASSUME_NONNULL_BEGIN /// 控制图片在UIButton里的位置,默认为HDLOPButtonImagePositionLeft typedef NS_ENUM(NSUInteger, HDLEZOPButtonImagePosition) { HDLEZOPButtonImagePositionTop, // imageView在titleLabel上面 HDLEZOPButtonImagePositionLeft, // imageView在titleLabel左边 HDLEZOPButtonImagePositionBottom, // imageView在titleLabel下面 HDLEZOPButtonImagePositionRight, // imageView在titleLabel右边 }; @interface HDLEZOPButton : UIButton /** * 子类继承时重写的方法,一般不建议重写 initWithXxx */ - (void)didInitialize NS_REQUIRES_SUPER; /** * 让按钮的文字颜色自动跟随tintColor调整(系统默认titleColor是不跟随的)<br/> * 默认为NO */ @property(nonatomic, assign) IBInspectable BOOL adjustsTitleTintColorAutomatically; /** * 让按钮的图片颜色自动跟随tintColor调整(系统默认image是需要更改renderingMode才可以达到这种效果)<br/> * 默认为NO */ @property(nonatomic, assign) IBInspectable BOOL adjustsImageTintColorAutomatically; /** * 等价于 adjustsTitleTintColorAutomatically = YES & adjustsImageTintColorAutomatically = YES & tintColor = xxx * @warning 不支持传 nil */ @property(nonatomic, strong) IBInspectable UIColor *tintColorAdjustsTitleAndImage; /** * 是否自动调整highlighted时的按钮样式,默认为YES。<br/> * 当值为YES时,按钮highlighted时会改变自身的alpha属性为<b>ButtonHighlightedAlpha</b> */ @property(nonatomic, assign) IBInspectable BOOL adjustsButtonWhenHighlighted; /** * 是否自动调整disabled时的按钮样式,默认为YES。<br/> * 当值为YES时,按钮disabled时会改变自身的alpha属性为<b>ButtonDisabledAlpha</b> */ @property(nonatomic, assign) IBInspectable BOOL adjustsButtonWhenDisabled; /** * 设置按钮点击时的背景色,默认为nil。 * @warning 不支持带透明度的背景颜色。当设置highlightedBackgroundColor时,会强制把adjustsButtonWhenHighlighted设为NO,避免两者效果冲突。 * @see adjustsButtonWhenHighlighted */ @property(nonatomic, strong, nullable) IBInspectable UIColor *highlightedBackgroundColor; /** * 设置按钮点击时的边框颜色,默认为nil。 * @warning 当设置highlightedBorderColor时,会强制把adjustsButtonWhenHighlighted设为NO,避免两者效果冲突。 * @see adjustsButtonWhenHighlighted */ @property(nonatomic, strong, nullable) IBInspectable UIColor *highlightedBorderColor; /** * 设置按钮里图标和文字的相对位置,默认为HDLOPButtonImagePositionLeft<br/> * 可配合imageEdgeInsets、titleEdgeInsets、contentHorizontalAlignment、contentVerticalAlignment使用 */ @property(nonatomic, assign) HDLEZOPButtonImagePosition imagePosition; /** * 设置按钮里图标和文字之间的间隔,会自动响应 imagePosition 的变化而变化,默认为0。<br/> * 系统默认实现需要同时设置 titleEdgeInsets 和 imageEdgeInsets,同时还需考虑 contentEdgeInsets 的增加(否则不会影响布局,可能会让图标或文字溢出或挤压),使用该属性可以避免以上情况。<br/> * @warning 会与 imageEdgeInsets、 titleEdgeInsets、 contentEdgeInsets 共同作用。 */ @property(nonatomic, assign) IBInspectable CGFloat spacingBetweenImageAndTitle; @property(nonatomic, assign) IBInspectable CGFloat cornerRadius UI_APPEARANCE_SELECTOR;// 默认为 0。将其设置为 HDLOPButtonCornerRadiusAdjustsBounds 可自动保持圆角为按钮高度的一半。 @end NS_ASSUME_NONNULL_END EZSDK/EZSDK/EZ/Base/HDLEZOPButton.m
New file @@ -0,0 +1,729 @@ // // HDLEZOPButton.m // EZSDK // // Created by Davin on 2023/6/20. // #import "HDLEZOPButton.h" #define HDLOPScreenScale ([[UIScreen mainScreen] scale]) #pragma mark - Clang #define ArgumentToString(macro) #macro #define ClangWarningConcat(warning_name) ArgumentToString(clang diagnostic ignored warning_name) /// 参数可直接传入 clang 的 warning 名,warning 列表参考:https://clang.llvm.org/docs/DiagnosticsReference.html #define BeginIgnoreClangWarning(warningName) _Pragma("clang diagnostic push") _Pragma(ClangWarningConcat(#warningName)) #define EndIgnoreClangWarning _Pragma("clang diagnostic pop") #define HDLOPBeginIgnorePerformSelectorLeaksWarning BeginIgnoreClangWarning(-Warc-performSelector-leaks) #define HDLOPEndIgnorePerformSelectorLeaksWarning EndIgnoreClangWarning #define CGSizeMax CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) CG_INLINE CGFloat removeFloatMin(CGFloat floatValue) { return floatValue == CGFLOAT_MIN ? 0 : floatValue; } CG_INLINE CGFloat flatSpecificScale(CGFloat floatValue, CGFloat scale) { floatValue = removeFloatMin(floatValue); scale = scale ?: HDLOPScreenScale; CGFloat flattedValue = ceil(floatValue * scale) / scale; return flattedValue; } CG_INLINE CGFloat flat(CGFloat floatValue) { return flatSpecificScale(floatValue, 0); } CG_INLINE UIEdgeInsets UIEdgeInsetsRemoveFloatMin(UIEdgeInsets insets) { UIEdgeInsets result = UIEdgeInsetsMake(removeFloatMin(insets.top), removeFloatMin(insets.left), removeFloatMin(insets.bottom), removeFloatMin(insets.right)); return result; } /// 获取UIEdgeInsets在水平方向上的值 CG_INLINE CGFloat UIEdgeInsetsGetHorizontalValue(UIEdgeInsets insets) { return insets.left + insets.right; } /// 获取UIEdgeInsets在垂直方向上的值 CG_INLINE CGFloat UIEdgeInsetsGetVerticalValue(UIEdgeInsets insets) { return insets.top + insets.bottom; } /// 传入size,返回一个x/y为0的CGRect CG_INLINE CGRect CGRectMakeWithSize(CGSize size) { return CGRectMake(0, 0, size.width, size.height); } CG_INLINE CGRect CGRectSetX(CGRect rect, CGFloat x) { rect.origin.x = flat(x); return rect; } CG_INLINE CGRect CGRectSetY(CGRect rect, CGFloat y) { rect.origin.y = flat(y); return rect; } CG_INLINE CGRect CGRectSetXY(CGRect rect, CGFloat x, CGFloat y) { rect.origin.x = flat(x); rect.origin.y = flat(y); return rect; } CG_INLINE CGRect CGRectSetWidth(CGRect rect, CGFloat width) { if (width < 0) { return rect; } rect.size.width = flat(width); return rect; } CG_INLINE CGRect CGRectSetHeight(CGRect rect, CGFloat height) { if (height < 0) { return rect; } rect.size.height = flat(height); return rect; } /// 将一个 CGSize 像素对齐 CG_INLINE CGSize CGSizeFlatted(CGSize size) { return CGSizeMake(flat(size.width), flat(size.height)); } CG_INLINE CGRect CGRectSetSize(CGRect rect, CGSize size) { rect.size = CGSizeFlatted(size); return rect; } /// 用于居中运算 CG_INLINE CGFloat CGFloatGetCenter(CGFloat parent, CGFloat child) { return flat((parent - child) / 2.0); } /// 对CGRect的x/y、width/height都调用一次flat,以保证像素对齐 CG_INLINE CGRect CGRectFlatted(CGRect rect) { return CGRectMake(flat(rect.origin.x), flat(rect.origin.y), flat(rect.size.width), flat(rect.size.height)); } /// 判断一个 CGSize 是否为空(宽或高为0) CG_INLINE BOOL CGSizeIsEmpty(CGSize size) { return size.width <= 0 || size.height <= 0; } const CGFloat HDLOPButtonCornerRadiusAdjustsBounds = -1; @interface HDLEZOPButton () @property(nonatomic, strong) CALayer *highlightedBackgroundLayer; @property(nonatomic, strong) UIColor *originBorderColor; @end @implementation HDLEZOPButton - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.tintColor = HDLEZHEXCOLOR(0x5C62FE,0.1); [self setTitleColor:self.tintColor forState:UIControlStateNormal];// 初始化时 adjustsTitleTintColorAutomatically 还是 NO,所以这里手动把 titleColor 设置为 tintColor 的值 // iOS7以后的button,sizeToFit后默认会自带一个上下的contentInsets,为了保证按钮大小即为内容大小,这里直接去掉,改为一个最小的值。 self.contentEdgeInsets = UIEdgeInsetsMake(CGFLOAT_MIN, 0, CGFLOAT_MIN, 0); // 放在后面,让前面的默认值可以被子类重写的 didInitialize 覆盖 [self didInitialize]; } return self; } - (instancetype)initWithCoder:(NSCoder *)aDecoder { if (self = [super initWithCoder:aDecoder]) { [self didInitialize]; } return self; } - (void)didInitialize { // 默认接管highlighted和disabled的表现,去掉系统默认的表现 self.adjustsImageWhenHighlighted = NO; self.adjustsImageWhenDisabled = NO; self.adjustsButtonWhenHighlighted = YES; self.adjustsButtonWhenDisabled = YES; // 图片默认在按钮左边,与系统UIButton保持一致 self.imagePosition = HDLEZOPButtonImagePositionLeft; } // 系统访问 self.imageView 会触发 layout,而私有方法 _imageView 则是简单地访问 imageView,所以在 HDLOPButton layoutSubviews 里应该用这个方法 - (UIImageView *)_hdlop_imageView { HDLOPBeginIgnorePerformSelectorLeaksWarning return [self performSelector:NSSelectorFromString(@"_imageView")]; HDLOPEndIgnorePerformSelectorLeaksWarning } - (CGSize)sizeThatFits:(CGSize)size { // 如果调用 sizeToFit,那么传进来的 size 就是当前按钮的 size,此时的计算不要去限制宽高 // 系统 UIButton 不管任何时候,对 sizeThatFits:CGSizeZero 都会返回真实的内容大小,这里对齐 if (CGSizeEqualToSize(self.bounds.size, size) || CGSizeIsEmpty(size)) { size = CGSizeMax; } BOOL isImageViewShowing = !!self.currentImage; BOOL isTitleLabelShowing = !!self.currentTitle || self.currentAttributedTitle; CGSize imageTotalSize = CGSizeZero;// 包含 imageEdgeInsets 那些空间 CGSize titleTotalSize = CGSizeZero;// 包含 titleEdgeInsets 那些空间 CGFloat spacingBetweenImageAndTitle = flat(isImageViewShowing && isTitleLabelShowing ? self.spacingBetweenImageAndTitle : 0);// 如果图片或文字某一者没显示,则这个 spacing 不考虑进布局 UIEdgeInsets contentEdgeInsets = UIEdgeInsetsRemoveFloatMin(self.contentEdgeInsets); CGSize resultSize = CGSizeZero; CGSize contentLimitSize = CGSizeMake(size.width - UIEdgeInsetsGetHorizontalValue(contentEdgeInsets), size.height - UIEdgeInsetsGetVerticalValue(contentEdgeInsets)); switch (self.imagePosition) { case HDLEZOPButtonImagePositionTop: case HDLEZOPButtonImagePositionBottom: { // 图片和文字上下排版时,宽度以文字或图片的最大宽度为最终宽度 if (isImageViewShowing) { CGFloat imageLimitWidth = contentLimitSize.width - UIEdgeInsetsGetHorizontalValue(self.imageEdgeInsets); CGSize imageSize = self.imageView.image ? [self.imageView sizeThatFits:CGSizeMake(imageLimitWidth, CGFLOAT_MAX)] : self.currentImage.size; imageSize.width = MIN(imageSize.width, imageLimitWidth);// HDLOPButton sizeThatFits 时 self._imageView 为 nil 但 self.imageView 有值,而开启了 Bold Text 时,系统的 self.imageView sizeThatFits 返回值会比没开启 BoldText 时多 1pt(不知道为什么文字加粗与否会影响 imageView...),从而保证开启 Bold Text 后文字依然能完整展示出来,所以这里应该用 self.imageView 而不是 self._imageView imageTotalSize = CGSizeMake(imageSize.width + UIEdgeInsetsGetHorizontalValue(self.imageEdgeInsets), imageSize.height + UIEdgeInsetsGetVerticalValue(self.imageEdgeInsets)); } if (isTitleLabelShowing) { CGSize titleLimitSize = CGSizeMake(contentLimitSize.width - UIEdgeInsetsGetHorizontalValue(self.titleEdgeInsets), contentLimitSize.height - imageTotalSize.height - spacingBetweenImageAndTitle - UIEdgeInsetsGetVerticalValue(self.titleEdgeInsets)); CGSize titleSize = [self.titleLabel sizeThatFits:titleLimitSize]; titleSize.height = MIN(titleSize.height, titleLimitSize.height); titleTotalSize = CGSizeMake(titleSize.width + UIEdgeInsetsGetHorizontalValue(self.titleEdgeInsets), titleSize.height + UIEdgeInsetsGetVerticalValue(self.titleEdgeInsets)); } resultSize.width = UIEdgeInsetsGetHorizontalValue(contentEdgeInsets); resultSize.width += MAX(imageTotalSize.width, titleTotalSize.width); resultSize.height = UIEdgeInsetsGetVerticalValue(contentEdgeInsets) + imageTotalSize.height + spacingBetweenImageAndTitle + titleTotalSize.height; } break; case HDLEZOPButtonImagePositionLeft: case HDLEZOPButtonImagePositionRight: { // 图片和文字水平排版时,高度以文字或图片的最大高度为最终高度 // 注意这里有一个和系统不一致的行为:当 titleLabel 为多行时,系统的 sizeThatFits: 计算结果固定是单行的,所以当 HDLOPButtonImagePositionLeft 并且titleLabel 多行的情况下,HDLOPButton 计算的结果与系统不一致 if (isImageViewShowing) { CGFloat imageLimitHeight = contentLimitSize.height - UIEdgeInsetsGetVerticalValue(self.imageEdgeInsets); CGSize imageSize = self.imageView.image ? [self.imageView sizeThatFits:CGSizeMake(CGFLOAT_MAX, imageLimitHeight)] : self.currentImage.size; imageSize.height = MIN(imageSize.height, imageLimitHeight);// HDLOPButton sizeThatFits 时 self._imageView 为 nil 但 self.imageView 有值,而开启了 Bold Text 时,系统的 self.imageView sizeThatFits 返回值会比没开启 BoldText 时多 1pt(不知道为什么文字加粗与否会影响 imageView...),从而保证开启 Bold Text 后文字依然能完整展示出来,所以这里应该用 self.imageView 而不是 self._imageView imageTotalSize = CGSizeMake(imageSize.width + UIEdgeInsetsGetHorizontalValue(self.imageEdgeInsets), imageSize.height + UIEdgeInsetsGetVerticalValue(self.imageEdgeInsets)); } if (isTitleLabelShowing) { CGSize titleLimitSize = CGSizeMake(contentLimitSize.width - UIEdgeInsetsGetHorizontalValue(self.titleEdgeInsets) - imageTotalSize.width - spacingBetweenImageAndTitle, contentLimitSize.height - UIEdgeInsetsGetVerticalValue(self.titleEdgeInsets)); CGSize titleSize = [self.titleLabel sizeThatFits:titleLimitSize]; titleSize.height = MIN(titleSize.height, titleLimitSize.height); titleTotalSize = CGSizeMake(titleSize.width + UIEdgeInsetsGetHorizontalValue(self.titleEdgeInsets), titleSize.height + UIEdgeInsetsGetVerticalValue(self.titleEdgeInsets)); } resultSize.width = UIEdgeInsetsGetHorizontalValue(contentEdgeInsets) + imageTotalSize.width + spacingBetweenImageAndTitle + titleTotalSize.width; resultSize.height = UIEdgeInsetsGetVerticalValue(contentEdgeInsets); resultSize.height += MAX(imageTotalSize.height, titleTotalSize.height); } break; } return resultSize; } - (CGSize)intrinsicContentSize { return [self sizeThatFits:CGSizeMax]; } - (void)layoutSubviews { [super layoutSubviews]; if (CGRectIsEmpty(self.bounds)) { return; } if (self.cornerRadius == HDLOPButtonCornerRadiusAdjustsBounds) { self.layer.cornerRadius = CGRectGetHeight(self.bounds) / 2; } BOOL isImageViewShowing = !!self.currentImage; BOOL isTitleLabelShowing = !!self.currentTitle || !!self.currentAttributedTitle; CGSize imageLimitSize = CGSizeZero; CGSize titleLimitSize = CGSizeZero; CGSize imageTotalSize = CGSizeZero;// 包含 imageEdgeInsets 那些空间 CGSize titleTotalSize = CGSizeZero;// 包含 titleEdgeInsets 那些空间 CGFloat spacingBetweenImageAndTitle = flat(isImageViewShowing && isTitleLabelShowing ? self.spacingBetweenImageAndTitle : 0);// 如果图片或文字某一者没显示,则这个 spacing 不考虑进布局 CGRect imageFrame = CGRectZero; CGRect titleFrame = CGRectZero; UIEdgeInsets contentEdgeInsets = UIEdgeInsetsRemoveFloatMin(self.contentEdgeInsets); CGSize contentSize = CGSizeMake(CGRectGetWidth(self.bounds) - UIEdgeInsetsGetHorizontalValue(contentEdgeInsets), CGRectGetHeight(self.bounds) - UIEdgeInsetsGetVerticalValue(contentEdgeInsets)); // 图片的布局原则都是尽量完整展示,所以不管 imagePosition 的值是什么,这个计算过程都是相同的 if (isImageViewShowing) { imageLimitSize = CGSizeMake(contentSize.width - UIEdgeInsetsGetHorizontalValue(self.imageEdgeInsets), contentSize.height - UIEdgeInsetsGetVerticalValue(self.imageEdgeInsets)); CGSize imageSize = self._hdlop_imageView.image ? [self._hdlop_imageView sizeThatFits:imageLimitSize] : self.currentImage.size; imageSize.width = MIN(imageLimitSize.width, imageSize.width); imageSize.height = MIN(imageLimitSize.height, imageSize.height); imageFrame = CGRectMakeWithSize(imageSize); imageTotalSize = CGSizeMake(imageSize.width + UIEdgeInsetsGetHorizontalValue(self.imageEdgeInsets), imageSize.height + UIEdgeInsetsGetVerticalValue(self.imageEdgeInsets)); } // UIButton 如果本身大小为 (0,0),此时设置一个 imageEdgeInsets 会让 imageView 的 bounds 错误,导致后续 imageView 的 subviews 布局时会产生偏移,因此这里做一次保护 void (^makesureBoundsPositive)(UIView *) = ^void(UIView *view) { CGRect bounds = view.bounds; if (CGRectGetMinX(bounds) < 0 || CGRectGetMinY(bounds) < 0) { bounds = CGRectMakeWithSize(bounds.size); view.bounds = bounds; } }; if (isImageViewShowing) { makesureBoundsPositive(self._hdlop_imageView); } if (isTitleLabelShowing) { makesureBoundsPositive(self.titleLabel); } if (self.imagePosition == HDLEZOPButtonImagePositionTop || self.imagePosition == HDLEZOPButtonImagePositionBottom) { if (isTitleLabelShowing) { titleLimitSize = CGSizeMake(contentSize.width - UIEdgeInsetsGetHorizontalValue(self.titleEdgeInsets), contentSize.height - imageTotalSize.height - spacingBetweenImageAndTitle - UIEdgeInsetsGetVerticalValue(self.titleEdgeInsets)); CGSize titleSize = [self.titleLabel sizeThatFits:titleLimitSize]; titleSize.width = MIN(titleLimitSize.width, titleSize.width); titleSize.height = MIN(titleLimitSize.height, titleSize.height); titleFrame = CGRectMakeWithSize(titleSize); titleTotalSize = CGSizeMake(titleSize.width + UIEdgeInsetsGetHorizontalValue(self.titleEdgeInsets), titleSize.height + UIEdgeInsetsGetVerticalValue(self.titleEdgeInsets)); } switch (self.contentHorizontalAlignment) { case UIControlContentHorizontalAlignmentLeft: imageFrame = isImageViewShowing ? CGRectSetX(imageFrame, contentEdgeInsets.left + self.imageEdgeInsets.left) : imageFrame; titleFrame = isTitleLabelShowing ? CGRectSetX(titleFrame, contentEdgeInsets.left + self.titleEdgeInsets.left) : titleFrame; break; case UIControlContentHorizontalAlignmentCenter: imageFrame = isImageViewShowing ? CGRectSetX(imageFrame, contentEdgeInsets.left + self.imageEdgeInsets.left + CGFloatGetCenter(imageLimitSize.width, CGRectGetWidth(imageFrame))) : imageFrame; titleFrame = isTitleLabelShowing ? CGRectSetX(titleFrame, contentEdgeInsets.left + self.titleEdgeInsets.left + CGFloatGetCenter(titleLimitSize.width, CGRectGetWidth(titleFrame))) : titleFrame; break; case UIControlContentHorizontalAlignmentRight: imageFrame = isImageViewShowing ? CGRectSetX(imageFrame, CGRectGetWidth(self.bounds) - contentEdgeInsets.right - self.imageEdgeInsets.right - CGRectGetWidth(imageFrame)) : imageFrame; titleFrame = isTitleLabelShowing ? CGRectSetX(titleFrame, CGRectGetWidth(self.bounds) - contentEdgeInsets.right - self.titleEdgeInsets.right - CGRectGetWidth(titleFrame)) : titleFrame; break; case UIControlContentHorizontalAlignmentFill: if (isImageViewShowing) { imageFrame = CGRectSetX(imageFrame, contentEdgeInsets.left + self.imageEdgeInsets.left); imageFrame = CGRectSetWidth(imageFrame, imageLimitSize.width); } if (isTitleLabelShowing) { titleFrame = CGRectSetX(titleFrame, contentEdgeInsets.left + self.titleEdgeInsets.left); titleFrame = CGRectSetWidth(titleFrame, titleLimitSize.width); } break; default: break; } if (self.imagePosition == HDLEZOPButtonImagePositionTop) { switch (self.contentVerticalAlignment) { case UIControlContentVerticalAlignmentTop: imageFrame = isImageViewShowing ? CGRectSetY(imageFrame, contentEdgeInsets.top + self.imageEdgeInsets.top) : imageFrame; titleFrame = isTitleLabelShowing ? CGRectSetY(titleFrame, contentEdgeInsets.top + imageTotalSize.height + spacingBetweenImageAndTitle + self.titleEdgeInsets.top) : titleFrame; break; case UIControlContentVerticalAlignmentCenter: { CGFloat contentHeight = imageTotalSize.height + spacingBetweenImageAndTitle + titleTotalSize.height; CGFloat minY = CGFloatGetCenter(contentSize.height, contentHeight) + contentEdgeInsets.top; imageFrame = isImageViewShowing ? CGRectSetY(imageFrame, minY + self.imageEdgeInsets.top) : imageFrame; titleFrame = isTitleLabelShowing ? CGRectSetY(titleFrame, minY + imageTotalSize.height + spacingBetweenImageAndTitle + self.titleEdgeInsets.top) : titleFrame; } break; case UIControlContentVerticalAlignmentBottom: titleFrame = isTitleLabelShowing ? CGRectSetY(titleFrame, CGRectGetHeight(self.bounds) - contentEdgeInsets.bottom - self.titleEdgeInsets.bottom - CGRectGetHeight(titleFrame)) : titleFrame; imageFrame = isImageViewShowing ? CGRectSetY(imageFrame, CGRectGetHeight(self.bounds) - contentEdgeInsets.bottom - titleTotalSize.height - spacingBetweenImageAndTitle - self.imageEdgeInsets.bottom - CGRectGetHeight(imageFrame)) : imageFrame; break; case UIControlContentVerticalAlignmentFill: { if (isImageViewShowing && isTitleLabelShowing) { // 同时显示图片和 label 的情况下,图片高度按本身大小显示,剩余空间留给 label imageFrame = isImageViewShowing ? CGRectSetY(imageFrame, contentEdgeInsets.top + self.imageEdgeInsets.top) : imageFrame; titleFrame = isTitleLabelShowing ? CGRectSetY(titleFrame, contentEdgeInsets.top + imageTotalSize.height + spacingBetweenImageAndTitle + self.titleEdgeInsets.top) : titleFrame; titleFrame = isTitleLabelShowing ? CGRectSetHeight(titleFrame, CGRectGetHeight(self.bounds) - contentEdgeInsets.bottom - self.titleEdgeInsets.bottom - CGRectGetMinY(titleFrame)) : titleFrame; } else if (isImageViewShowing) { imageFrame = CGRectSetY(imageFrame, contentEdgeInsets.top + self.imageEdgeInsets.top); imageFrame = CGRectSetHeight(imageFrame, contentSize.height - UIEdgeInsetsGetVerticalValue(self.imageEdgeInsets)); } else { titleFrame = CGRectSetY(titleFrame, contentEdgeInsets.top + self.titleEdgeInsets.top); titleFrame = CGRectSetHeight(titleFrame, contentSize.height - UIEdgeInsetsGetVerticalValue(self.titleEdgeInsets)); } } break; } } else { switch (self.contentVerticalAlignment) { case UIControlContentVerticalAlignmentTop: titleFrame = isTitleLabelShowing ? CGRectSetY(titleFrame, contentEdgeInsets.top + self.titleEdgeInsets.top) : titleFrame; imageFrame = isImageViewShowing ? CGRectSetY(imageFrame, contentEdgeInsets.top + titleTotalSize.height + spacingBetweenImageAndTitle + self.imageEdgeInsets.top) : imageFrame; break; case UIControlContentVerticalAlignmentCenter: { CGFloat contentHeight = imageTotalSize.height + titleTotalSize.height + spacingBetweenImageAndTitle; CGFloat minY = CGFloatGetCenter(contentSize.height, contentHeight) + contentEdgeInsets.top; titleFrame = isTitleLabelShowing ? CGRectSetY(titleFrame, minY + self.titleEdgeInsets.top) : titleFrame; imageFrame = isImageViewShowing ? CGRectSetY(imageFrame, minY + titleTotalSize.height + spacingBetweenImageAndTitle + self.imageEdgeInsets.top) : imageFrame; } break; case UIControlContentVerticalAlignmentBottom: imageFrame = isImageViewShowing ? CGRectSetY(imageFrame, CGRectGetHeight(self.bounds) - contentEdgeInsets.bottom - self.imageEdgeInsets.bottom - CGRectGetHeight(imageFrame)) : imageFrame; titleFrame = isTitleLabelShowing ? CGRectSetY(titleFrame, CGRectGetHeight(self.bounds) - contentEdgeInsets.bottom - imageTotalSize.height - spacingBetweenImageAndTitle - self.titleEdgeInsets.bottom - CGRectGetHeight(titleFrame)) : titleFrame; break; case UIControlContentVerticalAlignmentFill: { if (isImageViewShowing && isTitleLabelShowing) { // 同时显示图片和 label 的情况下,图片高度按本身大小显示,剩余空间留给 label imageFrame = CGRectSetY(imageFrame, CGRectGetHeight(self.bounds) - contentEdgeInsets.bottom - self.imageEdgeInsets.bottom - CGRectGetHeight(imageFrame)); titleFrame = CGRectSetY(titleFrame, contentEdgeInsets.top + self.titleEdgeInsets.top); titleFrame = CGRectSetHeight(titleFrame, CGRectGetHeight(self.bounds) - contentEdgeInsets.bottom - imageTotalSize.height - spacingBetweenImageAndTitle - self.titleEdgeInsets.bottom - CGRectGetMinY(titleFrame)); } else if (isImageViewShowing) { imageFrame = CGRectSetY(imageFrame, contentEdgeInsets.top + self.imageEdgeInsets.top); imageFrame = CGRectSetHeight(imageFrame, contentSize.height - UIEdgeInsetsGetVerticalValue(self.imageEdgeInsets)); } else { titleFrame = CGRectSetY(titleFrame, contentEdgeInsets.top + self.titleEdgeInsets.top); titleFrame = CGRectSetHeight(titleFrame, contentSize.height - UIEdgeInsetsGetVerticalValue(self.titleEdgeInsets)); } } break; } } if (isImageViewShowing) { imageFrame = CGRectFlatted(imageFrame); self._hdlop_imageView.frame = imageFrame; } if (isTitleLabelShowing) { titleFrame = CGRectFlatted(titleFrame); self.titleLabel.frame = titleFrame; } } else if (self.imagePosition == HDLEZOPButtonImagePositionLeft || self.imagePosition == HDLEZOPButtonImagePositionRight) { if (isTitleLabelShowing) { titleLimitSize = CGSizeMake(contentSize.width - UIEdgeInsetsGetHorizontalValue(self.titleEdgeInsets) - imageTotalSize.width - spacingBetweenImageAndTitle, contentSize.height - UIEdgeInsetsGetVerticalValue(self.titleEdgeInsets)); CGSize titleSize = [self.titleLabel sizeThatFits:titleLimitSize]; titleSize.width = MIN(titleLimitSize.width, titleSize.width); titleSize.height = MIN(titleLimitSize.height, titleSize.height); titleFrame = CGRectMakeWithSize(titleSize); titleTotalSize = CGSizeMake(titleSize.width + UIEdgeInsetsGetHorizontalValue(self.titleEdgeInsets), titleSize.height + UIEdgeInsetsGetVerticalValue(self.titleEdgeInsets)); } switch (self.contentVerticalAlignment) { case UIControlContentVerticalAlignmentTop: imageFrame = isImageViewShowing ? CGRectSetY(imageFrame, contentEdgeInsets.top + self.imageEdgeInsets.top) : imageFrame; titleFrame = isTitleLabelShowing ? CGRectSetY(titleFrame, contentEdgeInsets.top + self.titleEdgeInsets.top) : titleFrame; break; case UIControlContentVerticalAlignmentCenter: imageFrame = isImageViewShowing ? CGRectSetY(imageFrame, contentEdgeInsets.top + CGFloatGetCenter(contentSize.height, CGRectGetHeight(imageFrame)) + self.imageEdgeInsets.top) : imageFrame; titleFrame = isTitleLabelShowing ? CGRectSetY(titleFrame, contentEdgeInsets.top + CGFloatGetCenter(contentSize.height, CGRectGetHeight(titleFrame)) + self.titleEdgeInsets.top) : titleFrame; break; case UIControlContentVerticalAlignmentBottom: imageFrame = isImageViewShowing ? CGRectSetY(imageFrame, CGRectGetHeight(self.bounds) - contentEdgeInsets.bottom - self.imageEdgeInsets.bottom - CGRectGetHeight(imageFrame)) : imageFrame; titleFrame = isTitleLabelShowing ? CGRectSetY(titleFrame, CGRectGetHeight(self.bounds) - contentEdgeInsets.bottom - self.titleEdgeInsets.bottom - CGRectGetHeight(titleFrame)) : titleFrame; break; case UIControlContentVerticalAlignmentFill: if (isImageViewShowing) { imageFrame = CGRectSetY(imageFrame, contentEdgeInsets.top + self.imageEdgeInsets.top); imageFrame = CGRectSetHeight(imageFrame, contentSize.height - UIEdgeInsetsGetVerticalValue(self.imageEdgeInsets)); } if (isTitleLabelShowing) { titleFrame = CGRectSetY(titleFrame, contentEdgeInsets.top + self.titleEdgeInsets.top); titleFrame = CGRectSetHeight(titleFrame, contentSize.height - UIEdgeInsetsGetVerticalValue(self.titleEdgeInsets)); } break; } if (self.imagePosition == HDLEZOPButtonImagePositionLeft) { switch (self.contentHorizontalAlignment) { case UIControlContentHorizontalAlignmentLeft: imageFrame = isImageViewShowing ? CGRectSetX(imageFrame, contentEdgeInsets.left + self.imageEdgeInsets.left) : imageFrame; titleFrame = isTitleLabelShowing ? CGRectSetX(titleFrame, contentEdgeInsets.left + imageTotalSize.width + spacingBetweenImageAndTitle + self.titleEdgeInsets.left) : titleFrame; break; case UIControlContentHorizontalAlignmentCenter: { CGFloat contentWidth = imageTotalSize.width + spacingBetweenImageAndTitle + titleTotalSize.width; CGFloat minX = contentEdgeInsets.left + CGFloatGetCenter(contentSize.width, contentWidth); imageFrame = isImageViewShowing ? CGRectSetX(imageFrame, minX + self.imageEdgeInsets.left) : imageFrame; titleFrame = isTitleLabelShowing ? CGRectSetX(titleFrame, minX + imageTotalSize.width + spacingBetweenImageAndTitle + self.titleEdgeInsets.left) : titleFrame; } break; case UIControlContentHorizontalAlignmentRight: { if (imageTotalSize.width + spacingBetweenImageAndTitle + titleTotalSize.width > contentSize.width) { // 图片和文字总宽超过按钮宽度,则优先完整显示图片 imageFrame = isImageViewShowing ? CGRectSetX(imageFrame, contentEdgeInsets.left + self.imageEdgeInsets.left) : imageFrame; titleFrame = isTitleLabelShowing ? CGRectSetX(titleFrame, contentEdgeInsets.left + imageTotalSize.width + spacingBetweenImageAndTitle + self.titleEdgeInsets.left) : titleFrame; } else { // 内容不超过按钮宽度,则靠右布局即可 titleFrame = isTitleLabelShowing ? CGRectSetX(titleFrame, CGRectGetWidth(self.bounds) - contentEdgeInsets.right - self.titleEdgeInsets.right - CGRectGetWidth(titleFrame)) : titleFrame; imageFrame = isImageViewShowing ? CGRectSetX(imageFrame, CGRectGetWidth(self.bounds) - contentEdgeInsets.right - titleTotalSize.width - spacingBetweenImageAndTitle - imageTotalSize.width + self.imageEdgeInsets.left) : imageFrame; } } break; case UIControlContentHorizontalAlignmentFill: { if (isImageViewShowing && isTitleLabelShowing) { // 同时显示图片和 label 的情况下,图片按本身宽度显示,剩余空间留给 label imageFrame = CGRectSetX(imageFrame, contentEdgeInsets.left + self.imageEdgeInsets.left); titleFrame = CGRectSetX(titleFrame, contentEdgeInsets.left + imageTotalSize.width + spacingBetweenImageAndTitle + self.titleEdgeInsets.left); titleFrame = CGRectSetWidth(titleFrame, CGRectGetWidth(self.bounds) - contentEdgeInsets.right - self.titleEdgeInsets.right - CGRectGetMinX(titleFrame)); } else if (isImageViewShowing) { imageFrame = CGRectSetX(imageFrame, contentEdgeInsets.left + self.imageEdgeInsets.left); imageFrame = CGRectSetWidth(imageFrame, contentSize.width - UIEdgeInsetsGetHorizontalValue(self.imageEdgeInsets)); } else { titleFrame = CGRectSetX(titleFrame, contentEdgeInsets.left + self.titleEdgeInsets.left); titleFrame = CGRectSetWidth(titleFrame, contentSize.width - UIEdgeInsetsGetHorizontalValue(self.titleEdgeInsets)); } } break; default: break; } } else { switch (self.contentHorizontalAlignment) { case UIControlContentHorizontalAlignmentLeft: { if (imageTotalSize.width + spacingBetweenImageAndTitle + titleTotalSize.width > contentSize.width) { // 图片和文字总宽超过按钮宽度,则优先完整显示图片 imageFrame = isImageViewShowing ? CGRectSetX(imageFrame, CGRectGetWidth(self.bounds) - contentEdgeInsets.right - self.imageEdgeInsets.right - CGRectGetWidth(imageFrame)) : imageFrame; titleFrame = isTitleLabelShowing ? CGRectSetX(titleFrame, CGRectGetWidth(self.bounds) - contentEdgeInsets.right - imageTotalSize.width - spacingBetweenImageAndTitle - titleTotalSize.width + self.titleEdgeInsets.left) : titleFrame; } else { // 内容不超过按钮宽度,则靠左布局即可 titleFrame = isTitleLabelShowing ? CGRectSetX(titleFrame, contentEdgeInsets.left + self.titleEdgeInsets.left) : titleFrame; imageFrame = isImageViewShowing ? CGRectSetX(imageFrame, contentEdgeInsets.left + titleTotalSize.width + spacingBetweenImageAndTitle + self.imageEdgeInsets.left) : imageFrame; } } break; case UIControlContentHorizontalAlignmentCenter: { CGFloat contentWidth = imageTotalSize.width + spacingBetweenImageAndTitle + titleTotalSize.width; CGFloat minX = contentEdgeInsets.left + CGFloatGetCenter(contentSize.width, contentWidth); titleFrame = isTitleLabelShowing ? CGRectSetX(titleFrame, minX + self.titleEdgeInsets.left) : titleFrame; imageFrame = isImageViewShowing ? CGRectSetX(imageFrame, minX + titleTotalSize.width + spacingBetweenImageAndTitle + self.imageEdgeInsets.left) : imageFrame; } break; case UIControlContentHorizontalAlignmentRight: imageFrame = isImageViewShowing ? CGRectSetX(imageFrame, CGRectGetWidth(self.bounds) - contentEdgeInsets.right - self.imageEdgeInsets.right - CGRectGetWidth(imageFrame)) : imageFrame; titleFrame = isTitleLabelShowing ? CGRectSetX(titleFrame, CGRectGetWidth(self.bounds) - contentEdgeInsets.right - imageTotalSize.width - spacingBetweenImageAndTitle - self.titleEdgeInsets.right - CGRectGetWidth(titleFrame)) : titleFrame; break; case UIControlContentHorizontalAlignmentFill: { if (isImageViewShowing && isTitleLabelShowing) { // 图片按自身大小显示,剩余空间由标题占满 imageFrame = CGRectSetX(imageFrame, CGRectGetWidth(self.bounds) - contentEdgeInsets.right - self.imageEdgeInsets.right - CGRectGetWidth(imageFrame)); titleFrame = CGRectSetX(titleFrame, contentEdgeInsets.left + self.titleEdgeInsets.left); titleFrame = CGRectSetWidth(titleFrame, CGRectGetMinX(imageFrame) - self.imageEdgeInsets.left - spacingBetweenImageAndTitle - self.titleEdgeInsets.right - CGRectGetMinX(titleFrame)); } else if (isImageViewShowing) { imageFrame = CGRectSetX(imageFrame, contentEdgeInsets.left + self.imageEdgeInsets.left); imageFrame = CGRectSetWidth(imageFrame, contentSize.width - UIEdgeInsetsGetHorizontalValue(self.imageEdgeInsets)); } else { titleFrame = CGRectSetX(titleFrame, contentEdgeInsets.left + self.titleEdgeInsets.left); titleFrame = CGRectSetWidth(titleFrame, contentSize.width - UIEdgeInsetsGetHorizontalValue(self.titleEdgeInsets)); } } break; default: break; } } if (isImageViewShowing) { imageFrame = CGRectFlatted(imageFrame); self._hdlop_imageView.frame = imageFrame; } if (isTitleLabelShowing) { titleFrame = CGRectFlatted(titleFrame); self.titleLabel.frame = titleFrame; } } } - (void)setSpacingBetweenImageAndTitle:(CGFloat)spacingBetweenImageAndTitle { _spacingBetweenImageAndTitle = spacingBetweenImageAndTitle; [self setNeedsLayout]; } - (void)setImagePosition:(HDLEZOPButtonImagePosition)imagePosition { _imagePosition = imagePosition; [self setNeedsLayout]; } - (void)setHighlightedBackgroundColor:(UIColor *)highlightedBackgroundColor { _highlightedBackgroundColor = highlightedBackgroundColor; if (_highlightedBackgroundColor) { // 只要开启了highlightedBackgroundColor,就默认不需要alpha的高亮 self.adjustsButtonWhenHighlighted = NO; } } - (void)setHighlightedBorderColor:(UIColor *)highlightedBorderColor { _highlightedBorderColor = highlightedBorderColor; if (_highlightedBorderColor) { // 只要开启了highlightedBorderColor,就默认不需要alpha的高亮 self.adjustsButtonWhenHighlighted = NO; } } - (void)setHighlighted:(BOOL)highlighted { [super setHighlighted:highlighted]; if (highlighted && !self.originBorderColor) { // 手指按在按钮上会不断触发setHighlighted:,所以这里做了保护,设置过一次就不用再设置了 self.originBorderColor = [UIColor colorWithCGColor:self.layer.borderColor]; } // 渲染背景色 // if (self.highlightedBackgroundColor || self.highlightedBorderColor) { // [self adjustsButtonHighlighted]; // } // 如果此时是disabled,则disabled的样式优先 if (!self.enabled) { return; } // 自定义highlighted样式 // if (self.adjustsButtonWhenHighlighted) { // if (highlighted) { // self.alpha = ButtonHighlightedAlpha; // } else { // self.alpha = 1; // } // } } - (void)setEnabled:(BOOL)enabled { [super setEnabled:enabled]; if (!enabled && self.adjustsButtonWhenDisabled) { // self.alpha = ButtonDisabledAlpha; self.alpha = 1; } else { self.alpha = 1; } } //- (void)adjustsButtonHighlighted { // if (self.highlightedBackgroundColor) { // if (!self.highlightedBackgroundLayer) { // self.highlightedBackgroundLayer = [CALayer layer]; // [self.highlightedBackgroundLayer qmui_removeDefaultAnimations]; // [self.layer insertSublayer:self.highlightedBackgroundLayer atIndex:0]; // } // self.highlightedBackgroundLayer.frame = self.bounds; // self.highlightedBackgroundLayer.cornerRadius = self.layer.cornerRadius; // self.highlightedBackgroundLayer.maskedCorners = self.layer.maskedCorners; // self.highlightedBackgroundLayer.backgroundColor = self.highlighted ? self.highlightedBackgroundColor.CGColor : UIColorClear.CGColor; // } // // if (self.highlightedBorderColor) { // self.layer.borderColor = self.highlighted ? self.highlightedBorderColor.CGColor : self.originBorderColor.CGColor; // } //} - (void)setAdjustsTitleTintColorAutomatically:(BOOL)adjustsTitleTintColorAutomatically { _adjustsTitleTintColorAutomatically = adjustsTitleTintColorAutomatically; [self updateTitleColorIfNeeded]; } - (void)updateTitleColorIfNeeded { if (self.adjustsTitleTintColorAutomatically && self.currentTitleColor) { [self setTitleColor:self.tintColor forState:UIControlStateNormal]; } if (self.adjustsTitleTintColorAutomatically && self.currentAttributedTitle) { NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:self.currentAttributedTitle]; [attributedString addAttribute:NSForegroundColorAttributeName value:self.tintColor range:NSMakeRange(0, attributedString.length)]; [self setAttributedTitle:attributedString forState:UIControlStateNormal]; } } - (void)setAdjustsImageTintColorAutomatically:(BOOL)adjustsImageTintColorAutomatically { BOOL valueDifference = _adjustsImageTintColorAutomatically != adjustsImageTintColorAutomatically; _adjustsImageTintColorAutomatically = adjustsImageTintColorAutomatically; if (valueDifference) { [self updateImageRenderingModeIfNeeded]; } } - (void)updateImageRenderingModeIfNeeded { if (self.currentImage) { NSArray<NSNumber *> *states = @[@(UIControlStateNormal), @(UIControlStateHighlighted), @(UIControlStateSelected), @(UIControlStateSelected|UIControlStateHighlighted), @(UIControlStateDisabled)]; for (NSNumber *number in states) { UIImage *image = [self imageForState:number.unsignedIntegerValue]; if (!image) { continue; } if (number.unsignedIntegerValue != UIControlStateNormal && image == [self imageForState:UIControlStateNormal]) { continue; } if (self.adjustsImageTintColorAutomatically) { // 这里的 setImage: 操作不需要使用 renderingMode 对 image 重新处理,而是放到重写的 setImage:forState 里去做就行了 [self setImage:image forState:[number unsignedIntegerValue]]; } else { // 如果不需要用template的模式渲染,并且之前是使用template的,则把renderingMode改回Original [self setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:[number unsignedIntegerValue]]; } } } } - (void)setImage:(UIImage *)image forState:(UIControlState)state { if (self.adjustsImageTintColorAutomatically) { image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; } [super setImage:image forState:state]; } - (void)tintColorDidChange { [super tintColorDidChange]; [self updateTitleColorIfNeeded]; if (self.adjustsImageTintColorAutomatically) { [self updateImageRenderingModeIfNeeded]; } } - (void)setTintColorAdjustsTitleAndImage:(UIColor *)tintColorAdjustsTitleAndImage { _tintColorAdjustsTitleAndImage = tintColorAdjustsTitleAndImage; if (tintColorAdjustsTitleAndImage) { self.tintColor = tintColorAdjustsTitleAndImage; self.adjustsTitleTintColorAutomatically = YES; self.adjustsImageTintColorAutomatically = YES; } } - (void)setCornerRadius:(CGFloat)cornerRadius { _cornerRadius = cornerRadius; if (cornerRadius != HDLOPButtonCornerRadiusAdjustsBounds) { self.layer.cornerRadius = cornerRadius; } [self setNeedsLayout]; } @end EZSDK/EZSDK/EZ/TempPassword/Controllers/HDLEZDeviceMsgListViewController.m
@@ -28,7 +28,8 @@ @property (nonatomic, assign) NSInteger pageSize;//分页容量 @property (nonatomic, strong) NSMutableArray <MWPhoto *>*photos; // 预览图片信息 @property (nonatomic, strong) NSMutableArray <MWPhoto *>*photos; // 预览图片信息 @property (nonatomic, strong) NSString *currentPreviewPhoto; // 当前预览的图片 @end @@ -114,6 +115,31 @@ weakSelf.msgListV.msgList=weakSelf.msgList; weakSelf.currentPageNo+=1; }else{ #warning mock if (weakSelf.msgList.count == 0) { HDLEZDeviceMsgInfoModel *model = [[HDLEZDeviceMsgInfoModel alloc] init]; model.title = @"mock title 你好你好我是超长的测试标题,你来看下是否超出长度,你好你好我是超长的测试标题,你来看下是否超出长度"; model.createTime = @"2023.06.15"; model.content = @"mock content"; model.imageUrl = @"https://upload-images.jianshu.io/upload_images/5809200-a99419bb94924e6d.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240"; [weakSelf.msgList addObject:model]; HDLEZDeviceMsgInfoModel *model1 = [[HDLEZDeviceMsgInfoModel alloc] init]; model1.title = @"mock title1,你好你好"; model1.createTime = @"2023.06.15"; model1.content = @"mock content1"; model1.imageUrl = @"http://b.hiphotos.baidu.com/image/pic/item/e824b899a9014c08878b2c4c0e7b02087af4f4a3.jpg"; [weakSelf.msgList addObject:model1]; HDLEZDeviceMsgInfoModel *model2 = [[HDLEZDeviceMsgInfoModel alloc] init]; model2.title = @"mock title2"; model2.createTime = @"2023.06.15"; model2.content = @"mock content2"; model2.imageUrl = @"https://fastly.picsum.photos/id/452/1000/3000.jpg?hmac=g6GQYs1wmiPeoKOdwI3ot1y4MInIj_dnPk_jCYbVYfk"; [weakSelf.msgList addObject:model2]; } weakSelf.msgListV.msgList=weakSelf.msgList; [weakSelf.footer endRefreshingWithNoMoreData]; } @@ -143,8 +169,11 @@ - (void)didClickDownLoad:(MWPhotoBrowser *)photoBrowser { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSURL *url = [NSURL URLWithString:@"https://upload-images.jianshu.io/upload_images/5809200-a99419bb94924e6d.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240"]; if (!self.currentPreviewPhoto || self.currentPreviewPhoto.length == 0) { [UIView dd_showMessage:NSLocalizedString(@"device_save_gallery_failure", @"下载失败")]; return; } NSURL *url = [NSURL URLWithString:self.currentPreviewPhoto]; SDWebImageManager *manager = [SDWebImageManager sharedManager]; UIImage *img; if ([manager diskImageExistsForURL:url]) { @@ -179,6 +208,7 @@ #pragma mark PrivateMethod - (void)previewPictureWithUrl:(NSString *)picUrl { self.currentPreviewPhoto = picUrl; self.photos = [NSMutableArray array]; [self.photos addObject:[MWPhoto photoWithURL:[NSURL URLWithString:picUrl]]]; MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self]; EZSDK/EZSDK/EZ/TempPassword/Models/HDLEZDeviceMsgInfoModel.h
@@ -14,6 +14,7 @@ @property (nonatomic, copy)NSString *content;//内容 @property (nonatomic, copy)NSString *level;//消息等级 @property (nonatomic, copy)NSString *createTime;//创建时间 @property (nonatomic, copy)NSString *imageUrl;//截屏图片链接 @end NS_ASSUME_NONNULL_END EZSDK/EZSDK/EZ/TempPassword/Views/HDLEZDeviceMsgListView.m
@@ -30,6 +30,9 @@ self.delegate = self; self.dataSource = self; cellHeight=80; self.rowHeight = UITableViewAutomaticDimension; self.estimatedRowHeight = 80; [self registerClass:[HDLEZVideoDoorMsgCell class] forCellReuseIdentifier:@"HDLEZVideoDoorMsgCell"]; [self setSeparatorInset:UIEdgeInsetsZero]; // [self setLayoutMargins:UIEdgeInsetsZero]; } @@ -46,12 +49,12 @@ } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return cellHeight; return UITableViewAutomaticDimension; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ HDLEZLog(@"初始化cell"); HDLEZVideoDoorMsgCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HDLEZVideoDoorMsgCell"]; HDLEZVideoDoorMsgCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HDLEZVideoDoorMsgCell" forIndexPath:indexPath]; if(cell == nil){ cell=[[HDLEZVideoDoorMsgCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"HDLEZVideoDoorMsgCell"]; } @@ -71,10 +74,8 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (self.msgList.count <= indexPath.row) return; HDLEZDeviceMsgInfoModel *messageModel = self.msgList[indexPath.row]; #warning mock NSString *tempPicUrl = @"https://upload-images.jianshu.io/upload_images/5809200-a99419bb94924e6d.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240"; if (self.previewPic) { self.previewPic(tempPicUrl); self.previewPic(messageModel.imageUrl); } } @@ -88,9 +89,16 @@ if (self.msgList.count <= indexPath.row) return; HDLEZDeviceMsgInfoModel *messageModel = self.msgList[indexPath.row]; #warning mock NSString *tempPicUrl = @"https://upload-images.jianshu.io/upload_images/5809200-a99419bb94924e6d.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240"; [cell configMessageInfoWithTitle:messageModel.title deviceStatus:@"未接听" messageTime:messageModel.createTime messageImage:tempPicUrl]; NSString *stataus = @""; if (indexPath.row == 0) { stataus = @"未接"; } else if (indexPath.row == 1) { stataus = @"已接"; } [cell configMessageInfoWithTitle:messageModel.title deviceStatus:stataus messageTime:messageModel.createTime messageImage:indexPath.row != 0 ? messageModel.imageUrl : @""]; [cell showSpearator:(self.msgList.count != indexPath.row + 1)]; } /*设置消息列表值 EZSDK/EZSDK/EZ/TempPassword/Views/HDLEZVideoDoorMsgCell.h
@@ -19,6 +19,10 @@ /// - messageUrl: 消息图片 - (void)configMessageInfoWithTitle:(NSString *)title deviceStatus:(NSString *)deviceStatus messageTime:(NSString *)time messageImage:(NSString *)messageUrl; /// 是否展示分割线 /// - Parameter isShow: 是否展示 - (void)showSpearator:(BOOL)isShow; @end NS_ASSUME_NONNULL_END EZSDK/EZSDK/EZ/TempPassword/Views/HDLEZVideoDoorMsgCell.m
@@ -13,6 +13,7 @@ @property (strong, nonatomic) UILabel *statusLabel; @property (strong, nonatomic) UILabel *timeLabel; @property (strong, nonatomic) UIImageView *messageImageView; @property (strong, nonatomic) UIView *separatorLine; @end @@ -31,33 +32,40 @@ [self.contentView addSubview:self.statusLabel]; [self.contentView addSubview:self.timeLabel]; [self.contentView addSubview:self.messageImageView]; [self.contentView addSubview:self.separatorLine]; [self.messageTitle mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.contentView.mas_top).offset(16.); make.top.mas_equalTo(self.contentView.mas_top).offset(24.); make.left.mas_equalTo(self.contentView.mas_left).offset(16.); make.height.mas_equalTo(22); }]; [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.messageTitle.mas_bottom).offset(10.); make.left.mas_equalTo(self.messageTitle.mas_left); make.width.mas_equalTo(50); make.height.mas_equalTo(30); make.top.mas_equalTo(self.messageTitle.mas_top).offset(0.); make.left.mas_equalTo(self.messageTitle.mas_right).offset(8.); make.right.mas_lessThanOrEqualTo(self.messageImageView.mas_left).offset(-8.); make.width.mas_equalTo(40); make.height.mas_equalTo(20); }]; [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.messageTitle.mas_bottom).offset(4.); make.left.mas_equalTo(self.messageTitle.mas_left); make.bottom.mas_equalTo(self.messageImageView.mas_bottom); make.right.mas_equalTo(self.messageTitle.mas_right); make.height.mas_equalTo(22); make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-12.); make.height.mas_equalTo(17); }]; [self.messageImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.contentView.mas_top).offset(16.); make.left.mas_equalTo(self.messageTitle.mas_right).offset(10.); make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-16.); make.right.mas_equalTo(self.contentView.mas_right).offset(-16.); make.width.mas_equalTo(self.messageImageView.mas_height).multipliedBy(5/3.); make.centerY.mas_equalTo(self.contentView.mas_centerY); make.width.mas_equalTo(72.); make.height.mas_equalTo(41.); }]; [self.separatorLine mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.messageTitle.mas_left); make.bottom.mas_equalTo(self.contentView.mas_bottom); make.right.mas_equalTo(self.messageImageView.mas_right); make.height.mas_equalTo(0.5); }]; } @@ -66,16 +74,36 @@ if (title && title.length > 0) { self.messageTitle.text = title; } if (deviceStatus && deviceStatus.length > 0) { self.statusLabel.text = deviceStatus; [self.statusLabel mas_updateConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(40.); }]; self.statusLabel.backgroundColor = [deviceStatus isEqualToString:@"已接"] ? HDLEZHEXCOLOR(0x00C22D, 1.) : HDLEZHEXCOLOR(0xFF4747, 1.); } else { [self.statusLabel mas_updateConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(0.); }]; } if (time && time.length > 0) { self.timeLabel.text = time; } if (messageUrl && messageUrl.length > 0) { NSLog(@"#######cell image url:%@", messageUrl); [self.messageImageView sd_setImageWithURL:[NSURL URLWithString:messageUrl] placeholderImageScale:[UIImage imageNamed:@""]]; [self.messageImageView mas_updateConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(72.); }]; } else { [self.messageImageView mas_updateConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(0.); }]; } } - (void)showSpearator:(BOOL)isShow { self.separatorLine.hidden = !isShow; } #pragma mark - Getter @@ -84,6 +112,7 @@ _messageTitle=[[UILabel alloc] init]; _messageTitle.font = HDLEZ_Get_FontRegularWithSize(HDLEZ_FontSize_14); _messageTitle.textColor=HDLEZ_COLOR_TITLE_BLACK; _messageTitle.numberOfLines = 2; } return _messageTitle; } @@ -92,9 +121,9 @@ if (!_statusLabel) { _statusLabel=[[UILabel alloc] init]; _statusLabel.font = HDLEZ_Get_FontRegularWithSize(HDLEZ_FontSize_12); _statusLabel.textColor = HDLEZ_COLOR_TEXT_LIGHT_GRAY; _statusLabel.layer.cornerRadius = 5; _statusLabel.layer.borderColor = HDLEZ_COLOR_TEXT_GRAY.CGColor; _statusLabel.textColor = HDLEZ_COLOR_TEXT_WHITE; _statusLabel.textAlignment = NSTextAlignmentCenter; _statusLabel.layer.cornerRadius = 4; _statusLabel.clipsToBounds = YES; } return _statusLabel; @@ -104,8 +133,7 @@ if (!_timeLabel) { _timeLabel=[[UILabel alloc] init]; _timeLabel.font = HDLEZ_Get_FontRegularWithSize(HDLEZ_FontSize_12); _timeLabel.textColor=HDLEZ_COLOR_TEXT_GRAY; _timeLabel.textAlignment = NSTextAlignmentRight; _timeLabel.textColor=HDLEZ_COLOR_TEXT_LIGHT_GRAY; } return _timeLabel; } @@ -113,10 +141,20 @@ - (UIImageView *)messageImageView { if (!_messageImageView) { _messageImageView = [[UIImageView alloc] init]; _messageImageView.contentMode = UIViewContentModeScaleAspectFill; _messageImageView.backgroundColor = HDLEZ_COLOR_TEXT_LIGHT_GRAY; _messageImageView.layer.cornerRadius = 4; _messageImageView.clipsToBounds = YES; } return _messageImageView; } - (UIView *)separatorLine { if (!_separatorLine) { _separatorLine = [[UIView alloc] init]; _separatorLine.backgroundColor = HDLEZ_COLOR_BACKGROUND_LINE; } return _separatorLine; } @end EZSDK/EZSDK/EZ/UIViewControllers/EZLivePlayViewController.m
@@ -24,6 +24,7 @@ #import "MBProgressHUD.h" #import <EZOpenSDKFramework/EZPMPlayPrivateTokenInfo.h> #import "HDLEZAlertInputView.h" #import "HDLEZOPButton.h" #define MinimumZoomScale 1.0 #define MaximumZoomScale 4.0 @@ -101,9 +102,9 @@ // 呼叫视图相关控件 @property (weak, nonatomic) IBOutlet UIView *videoCallOutView; // 呼叫弹框 @property (weak, nonatomic) IBOutlet UILabel *callOutAlertLabel; // 提示语言 @property (weak, nonatomic) IBOutlet UIButton *hangUpButton; // 挂断按钮 @property (weak, nonatomic) IBOutlet UIButton *ignoreButton; // 忽略按钮 @property (weak, nonatomic) IBOutlet UIButton *answerButton; // 接听按钮 @property (weak, nonatomic) IBOutlet HDLEZOPButton *hangUpButton; // 挂断按钮 @property (weak, nonatomic) IBOutlet HDLEZOPButton *ignoreButton; // 忽略按钮 @property (weak, nonatomic) IBOutlet HDLEZOPButton *answerButton; // 接听按钮 @end @@ -342,6 +343,7 @@ self.localRecordButton.enabled = NO; self.streamPlayBtn.hidden = YES; self.isShowAlert = YES; NSLog(@"#####初始化方法展示"); if (_url) { @@ -476,11 +478,14 @@ self.callOutAlertLabel.text = HDLEZLocallizedString(@"device_callout_alert_message"); [self.hangUpButton setTitle:HDLEZLocallizedString(@"device_callout_hang_up") forState:UIControlStateNormal]; self.hangUpButton.imagePosition = HDLEZOPButtonImagePositionTop; self.hangUpButton.spacingBetweenImageAndTitle = 12.; [self.ignoreButton setTitle:HDLEZLocallizedString(@"device_callout_ignore") forState:UIControlStateNormal]; self.ignoreButton.imagePosition = HDLEZOPButtonImagePositionTop; self.ignoreButton.spacingBetweenImageAndTitle = 12.; [self.answerButton setTitle:HDLEZLocallizedString(@"device_callout_answer") forState:UIControlStateNormal]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ self.isShowAlert = NO; }); self.answerButton.imagePosition = HDLEZOPButtonImagePositionTop; self.answerButton.spacingBetweenImageAndTitle = 12.; } /*开锁 @@ -889,6 +894,7 @@ self.largeTitleLabel.hidden = NO; self.largeBackButton.hidden = YES; self.bottomView.hidden = YES; self.videoCallOutView.hidden = YES; [self.scrollView setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.toolBar setTranslatesAutoresizingMaskIntoConstraints:NO]; @@ -927,7 +933,6 @@ - (IBAction)largeBack:(id)sender { NSLog(@"######收回横屏!"); _landscape = NO; if (self.isVideoDoorLock) { self.navigationController.navigationBarHidden = NO; @@ -936,6 +941,7 @@ self.bottomView.hidden = NO; self.largeTitleLabel.hidden = YES; self.localRecrodContraint.constant = 10; self.videoCallOutView.hidden = !self.isShowAlert; [self.scrollView setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.toolBar setTranslatesAutoresizingMaskIntoConstraints:NO]; @@ -1351,14 +1357,18 @@ - (IBAction)clickCalloutHangupAction:(id)sender { [UIView dd_showMessage:@"挂断开发中..."]; self.isShowAlert = NO; } - (IBAction)clickCalloutIgnoreAction:(id)sender { [UIView dd_showMessage:@"忽略开发中..."]; self.isShowAlert = NO; } - (IBAction)clickCalloutAnswerAction:(id)sender { [UIView dd_showMessage:@"接听开发中..."]; self.isShowAlert = NO; [self talkButtonClicked:self.talkButton]; } @@ -1366,12 +1376,15 @@ /// 展示呼叫弹框 - (void)showCallOutAlertView { self.videoCallOutView.hidden = NO; [UIView dd_showMessage:@"展示呼叫弹框"]; NSLog(@"展示呼叫弹框"); } /// 隐藏呼叫弹框 - (void)hiddenCallOutAlertView { self.videoCallOutView.hidden = YES; [UIView dd_showMessage:@"隐藏呼叫弹框"]; NSLog(@"隐藏呼叫弹框"); } #pragma mark - Private Methods @@ -1633,8 +1646,10 @@ - (void)setIsShowAlert:(BOOL)isShowAlert { _isShowAlert = isShowAlert; if (isShowAlert) { NSLog(@"#####set方法展示"); [self showCallOutAlertView]; } else { NSLog(@"#####set方法隐藏"); [self hiddenCallOutAlertView]; } } EZSDK/EZSDK/EZ/Venders/MWPhotoBrowser/MWPhotoBrowser.m
@@ -1654,7 +1654,11 @@ if (!_downloadBtn) { _downloadBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_downloadBtn setTitle:HDLEZLocallizedString(@"hdl_ez_download") forState:UIControlStateNormal]; [_downloadBtn setTitleColor:HDLEZ_COLOR_TEXT_LIGHT_GRAY forState:UIControlStateNormal]; _downloadBtn.titleLabel.font = HDLEZ_Get_FontRegularWithSize(HDLEZ_FontSize_16); [_downloadBtn setTitleColor:HDLEZ_COLOR_TEXT_WHITE forState:UIControlStateNormal]; _downloadBtn.backgroundColor = HDLEZ_COLOR_BACKGROUND_BUTTON; _downloadBtn.layer.cornerRadius = 22.; _downloadBtn.clipsToBounds = YES; } return _downloadBtn; } @@ -1662,10 +1666,10 @@ - (void)showDownloadBtn { [self.view addSubview:self.downloadBtn]; [self.downloadBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.view.mas_left).offset(32.); make.bottom.mas_equalTo(self.view.mas_bottom).offset(-HDLEZ_APP_TAB_BOTTOM_HEIGHT - 16); make.width.mas_equalTo((HDLEZ_APP_SCREEN_WIDTH - 96) / 2.); make.height.mas_equalTo(50.); make.centerX.mas_equalTo(self.view.mas_centerX); make.bottom.mas_equalTo(self.view.mas_bottom).offset(-37); make.width.mas_equalTo(220.); make.height.mas_equalTo(44.); }]; [self.downloadBtn addTarget:self action:@selector(downLoadAction) forControlEvents:UIControlEventTouchUpInside]; }