cdts/xdts-ios 3/TreeHole/CYHResetCode/CYH/QMUIKit/UIKitExtensions/NSAttributedString+QMUI.h

105 lines
6.5 KiB
C
Raw Normal View History

2023-07-27 09:20:00 +08:00
/**
* Tencent is pleased to support the open source community by making QMUI_iOS available.
* Copyright (C) 2016-2021 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.
*/
//
// NSAttributedString+QMUI.h
// qmui
//
// Created by QMUI Team on 16/9/23.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "QMUIHelper.h"
#import "NSString+QMUI.h"
NS_ASSUME_NONNULL_BEGIN
/// 如果某个 NSAttributedString 是通过 +[NSAttributedString qmui_attributedStringWithImage:margins:] 创建的,则该 string 会被添加以这个 name 为 key 的 attribute值为 NSValue 包裹的 UIEdgeInsets。
UIKIT_EXTERN NSAttributedStringKey const QMUIImageMarginsAttributeName;
@interface NSAttributedString (QMUI)<QMUIStringProtocol>
/**
* @brief image NSTextAttachment NSAttributedString
* @note image [UIImage qmui_imageWithAttributedString:] image attributes image y 使
* @param image
*/
+ (instancetype)qmui_attributedStringWithImage:(UIImage *)image;
/**
* @brief image NSTextAttachment NSAttributedString attributes image
* @note image imagestring fontlineHeight attributes
* @param image
* @param attributes attributes
*/
+ (instancetype)qmui_attributedStringWithImage:(UIImage *)image alignByAttributes:(NSDictionary<NSAttributedStringKey,id> *)attributes;
/**
* @brief attributedString
* @param image
* @param offset 线 offset > 0
* @param leftMargin
* @param rightMargin
* @note leftMargin rightMargin 0
*/
+ (instancetype)qmui_attributedStringWithImage:(UIImage *)image baselineOffset:(CGFloat)offset leftMargin:(CGFloat)leftMargin rightMargin:(CGFloat)rightMargin DEPRECATED_MSG_ATTRIBUTE("由于命名、参数不够友好,内部用 baseline 的实现方式也可能影响输入框后续文本的样式,因此本方法废弃,请改为用 qmui_attributedStringWithImage:margins:");
/**
* @brief attributedString margins
* string QMUIImageMarginsAttributeName margins NSValue UIEdgeInsets
* @param image
* @param margins baseline
* top > 0
* top < 0
* left > 0
* right > 0
*/
+ (instancetype)qmui_attributedStringWithImage:(UIImage *)image margins:(UIEdgeInsets)margins;
/**
* @brief attributedString
* @param width
*/
+ (instancetype)qmui_attributedStringWithFixedSpace:(CGFloat)width;
@end
@interface UIImage (QMUI_NSAttributedStringSupports)
/**
*
*
* NSAttributedString UITextView @UITextView attributes attributes UITextView fonttypingAttributes UIImage NSTextAttachment NSTextAttacment attributes UITextView 12pt UIImage @c attributedString copy UIImage UIImage [NSAttributedString qmui_attributedStringWithImage:] NSAttributedString attributes NSAttributedString attributes image
*/
+ (nullable UIImage *)qmui_imageWithAttributedString:(NSAttributedString *)attributedString;
/**
UIImage [UIImage qmui_imageWithAttributedString:] 使 NSAttributedString
*/
@property(nullable, nonatomic, strong, readonly) NSAttributedString *qmui_attributedString;
/**
UIImage [UIImage qmui_imageWithAttributedString:] 使 NSAttributedString attributes
*/
@property(nullable, nonatomic, strong, readonly) NSDictionary<NSAttributedStringKey, id> *qmui_stringAttributes;
@end
@interface QMUIHelper (NSAttributedStringSupports)
/**
image sizeattributes fontlineHeight image attributes attributes
@param image image
@param attributes attributes
@return image -[NSAttributedString qmui_attributedStringWithImage:margins:] margins.top
*/
+ (CGFloat)topMarginForAttributedImage:(UIImage *)image attributes:(NSDictionary<NSAttributedStringKey, id> *)attributes;
@end
NS_ASSUME_NONNULL_END