You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
5.1 KiB
105 lines
5.1 KiB
1 year ago
|
/**
|
||
|
* Tencent is pleased to support the open source community by making QMUI_iOS available.
|
||
|
* Copyright (C) 2016-2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||
|
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||
|
* http://opensource.org/licenses/MIT
|
||
|
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||
|
*/
|
||
|
|
||
|
//
|
||
|
// QMUIButton.h
|
||
|
// qmui
|
||
|
//
|
||
|
// Created by QMUI Team on 14-7-7.
|
||
|
//
|
||
|
|
||
|
#import <UIKit/UIKit.h>
|
||
|
|
||
|
NS_ASSUME_NONNULL_BEGIN
|
||
|
|
||
|
/// 控制图片在UIButton里的位置,默认为QMUIButtonImagePositionLeft
|
||
|
typedef NS_ENUM(NSUInteger, QMUIButtonImagePosition) {
|
||
|
QMUIButtonImagePositionTop, // imageView在titleLabel上面
|
||
|
QMUIButtonImagePositionLeft, // imageView在titleLabel左边
|
||
|
QMUIButtonImagePositionBottom, // imageView在titleLabel下面
|
||
|
QMUIButtonImagePositionRight, // imageView在titleLabel右边
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* 提供以下功能:
|
||
|
* 1. 支持让文字和图片自动跟随 tintColor 变化(系统的 UIButton 默认是不响应 tintColor 的)
|
||
|
* 2. highlighted、disabled 状态均通过改变整个按钮的alpha来表现,无需分别设置不同 state 下的 titleColor、image。alpha 的值可在配置表里修改 ButtonHighlightedAlpha、ButtonDisabledAlpha。
|
||
|
* 3. 支持点击时改变背景色颜色(highlightedBackgroundColor)
|
||
|
* 4. 支持点击时改变边框颜色(highlightedBorderColor)
|
||
|
* 5. 支持设置图片相对于 titleLabel 的位置(imagePosition)
|
||
|
* 6. 支持设置图片和 titleLabel 之间的间距,无需自行调整 titleEdgeInests、imageEdgeInsets(spacingBetweenImageAndTitle)
|
||
|
* @warning QMUIButton 重新定义了 UIButton.titleEdgeInests、imageEdgeInsets、contentEdgeInsets 这三者的布局逻辑,sizeThatFits: 里会把 titleEdgeInests 和 imageEdgeInsets 也考虑在内(UIButton 不会),以使这三个接口的使用更符合直觉。
|
||
|
*/
|
||
|
@interface QMUIButton : 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;
|
||
|
|
||
|
/**
|
||
|
* 设置按钮里图标和文字的相对位置,默认为QMUIButtonImagePositionLeft<br/>
|
||
|
* 可配合imageEdgeInsets、titleEdgeInsets、contentHorizontalAlignment、contentVerticalAlignment使用
|
||
|
*/
|
||
|
@property(nonatomic, assign) QMUIButtonImagePosition imagePosition;
|
||
|
|
||
|
/**
|
||
|
* 设置按钮里图标和文字之间的间隔,会自动响应 imagePosition 的变化而变化,默认为0。<br/>
|
||
|
* 系统默认实现需要同时设置 titleEdgeInsets 和 imageEdgeInsets,同时还需考虑 contentEdgeInsets 的增加(否则不会影响布局,可能会让图标或文字溢出或挤压),使用该属性可以避免以上情况。<br/>
|
||
|
* @warning 会与 imageEdgeInsets、 titleEdgeInsets、 contentEdgeInsets 共同作用。
|
||
|
*/
|
||
|
@property(nonatomic, assign) IBInspectable CGFloat spacingBetweenImageAndTitle;
|
||
|
|
||
|
@end
|
||
|
|
||
|
NS_ASSUME_NONNULL_END
|