測(cè)試文本數(shù)據(jù)
//html標(biāo)簽圖片自適應(yīng)
NSString *detailTextString = [STNewsDetailManager htmlImageHeighAutoStr:string width:self.textView.width];
+(NSString*)htmlImageHeighAutoStr:(NSString*)htmlStr width:(CGFloat)width
{
? ? NSString*detailTextString =@"";
//? ? 根據(jù)圖片大小自適應(yīng)抬旺,圖片寬度小于width蟀俊,圖片不變旗扑,寬度大于width捎谨,自適應(yīng)到屏幕寬度
? ? if(![WDUtilisNullOrEmpty:htmlStr]) {
? ? ? ? detailTextString = [NSString stringWithFormat:@"img{max-width:%f !important;height:auto}%@",width,htmlStr];
? ? }
? ? returndetailTextString;
}
?//轉(zhuǎn)換成AttributedString提取圖片URL
? ? NSMutableAttributedString *firstPart = [[NSMutableAttributedString alloc] initWithString:detailText];
? ? [self getImageurlFromHtml:firstPart];
//手動(dòng)提取文本中的圖片URL
- (NSArray*) getImageurlFromHtml:(NSMutableAttributedString*) webString
{
? ? if(webString.length==0) {
? ? ? ? returnnil;
? ? }
? ? NSString*webStr? = [NSString stringWithFormat:@"%@",webString];
? ? self.imageurlArray = [NSMutableArray arrayWithCapacity:1];
? ? //標(biāo)簽匹配
? ? NSString*parten =@"<img(.*?)>";
? ? NSError* error =NULL;
? ? NSRegularExpression *reg = [NSRegularExpression regularExpressionWithPattern:parten options:0 error:&error];
? ? NSArray* match = [reg matchesInString:webStr options:0 range:NSMakeRange(0, [webString length] - 1)];
? ? for(NSTextCheckingResult* resultinmatch) {
?? ? ? ?//過(guò)去數(shù)組中的標(biāo)簽
? ? ? ? NSRangerange = [resultrange];
? ? ? ? NSString* subString = [webStrsubstringWithRange:range];
?? ? ? ?//從圖片中的標(biāo)簽中提取ImageURL
? ? ? ? NSRegularExpression *subReg = [NSRegularExpression regularExpressionWithPattern:@"http://(.*?)\"" options:0 error:NULL];
? ? ? ? NSArray* match = [subRegmatchesInString:subStringoptions:0range:NSMakeRange(0, [subStringlength] -1)];
? ? ? ? if(match.count>0) {
? ? ? ? ? ? NSTextCheckingResult* subRes = match[0];
? ? ? ? ? ? NSRangesubRange = [subResrange];
? ? ? ? ? ? subRange.length= subRange.length-1;
? ? ? ? ? ? NSString* imagekUrl = [subStringsubstringWithRange:subRange];
? ? ? ? }
? ? ? ? else{
? ? ? ? ? ? NSRegularExpression *subReg = [NSRegularExpression regularExpressionWithPattern:@"https://(.*?)\"" options:0 error:NULL];
? ? ? ? ? ? NSArray* match = [subRegmatchesInString:subStringoptions:0range:NSMakeRange(0, [subStringlength] -1)];
? ? ? ? ? ? if(match.count>0) {
? ? ? ? ? ? ? ? NSTextCheckingResult* subRes = match[0];
? ? ? ? ? ? ? ? NSRangesubRange = [subResrange];
? ? ? ? ? ? ? ? subRange.length= subRange.length-1;
? ? ? ? ? ? ? ? NSString* imagekUrl = [subStringsubstringWithRange:subRange];
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? return self.imageurlArray;
}
//給textView賦值
self.textView.asyncAttributStr = detailTextString;
//加載完成后的回調(diào)
__weak typeof (self) weakSelf = self;
? ? ?self.textView.attributeBlock = ^{
//找到每個(gè)圖片所在的位置
[weakSelf.textView.attributedText enumerateAttributesInRange:NSMakeRange(0,weakSelf.textView.attributedText.length) options:NSAttributedStringEnumerationReverse usingBlock:^(NSDictionary<NSAttributedStringKey,id> * _Nonnull attrs, NSRange range, BOOL * _Nonnull stop) {
? ? ? ? ? ? if(attrs[@"NSAttachment"]) {
? ? ? ? ? ? ? ? NSTextAttachment*attachment = attrs[@"NSAttachment"];
? ? ? ? ? ? ? ? if([attachment.fileTypecontainsString:@"png"] ||
? ? ? ? ? ? ? ? ? ? [attachment.fileTypecontainsString:@"jpg"] ||
? ? ? ? ? ? ? ? ? ? [attachment.fileTypecontainsString:@"jpeg"]||
? ? ? ? ? ? ? ? ? ? [attachment.fileTypecontainsString:@"bmp"]||
? ? ? ? ? ? ? ? ? ? [attachment.fileTypecontainsString:@"gif"]) {
? ? ? ? ? ? ? ? ? ? NSString*str = [NSStringstringWithFormat:@"%ld",(unsignedlong)range.location]
? ? ? ? ? ? ? ? ? ? [weakSelf.rangeArrinsertObject:stratIndex:0];
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }];
};
//點(diǎn)擊圖片出發(fā)的代理方法(ios11.1系統(tǒng)的手機(jī)觸發(fā)需要點(diǎn)擊事件稍長(zhǎng)诫尽,此問(wèn)題禀酱,沒(méi)有找到解決辦法,感覺(jué)是蘋(píng)果系統(tǒng)系統(tǒng)問(wèn)題)
- (BOOL)textView:(UITextView*)textView shouldInteractWithTextAttachment:(NSTextAttachment*)textAttachment inRange:(NSRange)characterRange{
? ? NSLog(@"點(diǎn)擊的第%lu個(gè)",(unsignedlong)characterRange.location);
? ? NSLog(@"圖片共%lu個(gè)",(unsignedlong)self.imageurlArray.count);
? ? NSString*location = [NSStringstringWithFormat:@"%ld",(unsignedlong)characterRange.location];
? ? if(self.rangeArr.count>0) {
? ? ? ? for(NSIntegeri =0; i
? ? ? ? ? ? NSString*str = [self.rangeArrobjectAtIndex:i];
? ? ? ? ? ? if([strisEqualToString:location] &&self.imageurlArray.count>=i+1) {
? ? ? ? ? ? ? ? if(self.imageBlock) {
? ? ?//根據(jù)自己的情況牧嫉,跳轉(zhuǎn)到圖片瀏覽頁(yè)面
? ? ? ? ? ? ? ? ? ? self.imageBlock(self,i,self.imageurlArray);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? return YES;
}
textView的初始化
- (STCustomTextView*)textView{?
? ? if(!_textView) {
? ? ? ? STCustomTextView *textView = [[STCustomTextView alloc] init];
? ? ? ? textView.myFont = [UIFont extFontOfSize:self.currentFontSize];
? ? ? ? textView.isAdjustHeightByWidth = YES;
? ? ? ? textView.lineRowSpacing=7;//行間距
? ? ? ? textView.lineAfterParagraphSpacing = 15;//段后間距
? ? ? ? textView.delegate=self;
? ? ? ? textView.backgroundColor = [ThemeManager _setupDayColor:nil nightColor:ST_Night_BackGroundColor];
? ? ? ? textView.myColor = [ThemeManager _setupDayColor:[WDUtil colorWithHexString:@"#181818"] nightColor:ST_Night_BigTitleColor];
? ? ? ? textView.editable=NO;? ? ? ? //必須禁止輸入剂跟,否則點(diǎn)擊將彈出輸入鍵盤(pán)
? ? ? ? textView.scrollEnabled=NO;
? ? ? ? _textView= textView;
? ? }
? ? return _textView;
}
自定義STCustomTextView
原本使用的是label,由于要加上點(diǎn)擊圖片瀏覽功能酣藻,所以換成了TextView曹洽,里面有些不用的代碼就給注釋了
.m文件
#import "STCustomTextView.h"
@implementationSTCustomTextView
-(instancetype)initWithFrame:(CGRect)frame
{
? ? self= [superinitWithFrame:frame];
? ? if(self) {
? ? ? ? //? ? ? ? _myLineBreakMode = NSLineBreakByWordWrapping;
//? ? ? ? _myAlignment = kMyTextAlignmentLeft;
? ? ? ? _isAdjustHeightByWidth = NO;
? ? ? ? _isAdjustWidthByHeight = NO;
? ? ? ? _isDestroyAttributeBlockAfterUse = NO;
? ? ? ? _lineRowSpacing = -1; //行間距
? ? ? ? _lineAfterParagraphSpacing = -1; //段前間距
? ? ? ? _lineBeforeParagraphSpacing = -1; //段后間距
? ? }
? ? return self;
}
#pragma mark - Set methods
#pragma mark 同步加載富文本 attributStr
-(void)setAttributStr:(NSString*)attributStr
{
? ? //? ? detailsModel.mainBody = @"測(cè)試";
? ? _attributStr= attributStr;
? ? self.attributedText= [selfaddMessageAttribute:attributStr];
? ? [self reloadAttributeData];
}
#pragma mark 異步加載富文本 asyncAttributStr
-(void)setAsyncAttributStr:(NSString*)asyncAttributStr
{
? ? _asyncAttributStr= asyncAttributStr;
? ? self.text=@"";//先清除文字再加載
? ? __weaktypeof(self) weakSelf =self;
? ? dispatch_async(dispatch_get_global_queue(0, 0), ^{
? ? ? ? NSMutableAttributedString*firstPart = [selfaddMessageAttribute:asyncAttributStr];
? ? ? ? dispatch_async(dispatch_get_main_queue(), ^{
? ? ? ? ? ? weakSelf.attributedText= firstPart;
? ? ? ? ? ? [weakSelfreloadAttributeData];
? ? ? ? ? ? [weakSelfinvocationAttributeBlock];
? ? ? ? });
? ? });
}
//編輯NSMutableAttributedString
-(NSMutableAttributedString*)addMessageAttribute:(NSString*)message
{
? ? //? ? message = [message stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%f.00pt",self.font.pointSize] withString:@"12.00pt"];
? ? //設(shè)置文字大小
? ? message = [NSString stringWithFormat:@"%@%@",self.font.pointSize,message,@""];
? ? NSMutableAttributedString *firstPart = [[NSMutableAttributedString alloc] initWithString:@""];
? ? @try{
? ? ? ? //空字符串直接返回nil
? ? ? ? if([selfisMessageNullOrEmpty:message]) {
? ? ? ? ? ? returnfirstPart;
? ? ? ? }
? ? ? ? firstPart = [[NSMutableAttributedString alloc]
?? ? ? ? ? ? ? ? ? ? initWithData:[message dataUsingEncoding:NSUnicodeStringEncoding]
?? ? ? ? ? ? ? ? ? ? options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}
?? ? ? ? ? ? ? ? ? ? documentAttributes:nil
?? ? ? ? ? ? ? ? ? ? error:nil];
? ? ? ? //? ? ? ? //文字大小
? ? ? ? //? ? ? ? [firstPart addAttribute:NSFontAttributeName
? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? value:self.font
? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? range:NSMakeRange(0, firstPart.length)];
? ? ? ? [firstPartaddAttribute:NSKernAttributeName
? ? ? ? ? ? ? ? ? ? ? ? ? value:@1.0f
? ? ? ? ? ? ? ? ? ? ? ? ? range:NSMakeRange(0, firstPart.length)];
? ? ? ? //沒(méi)有color,設(shè)置默認(rèn)顏色
? ? ? ? //? ? ? ? if (self.myColor && [self isNotHaveColorInString:message])
? ? ? ? if ([ThemeManager sharedThemeManager].isNight) {
? ? ? ? ? ? if(self.myColor){
? ? ? ? ? ? ? ? [firstPartaddAttribute:NSForegroundColorAttributeName
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? value:self.myColor
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? range:NSMakeRange(0, firstPart.length)];
? ? ? ? ? ? }
? ? ? ? }else{
? ? ? ? ? ? if(self.myColor&& [selfisNotHaveColorInString:message]){
? ? ? ? ? ? ? ? [firstPartaddAttribute:NSForegroundColorAttributeName
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? value:self.myColor
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? range:NSMakeRange(0, firstPart.length)];
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? if(self.lineRowSpacing>=0
? ? ? ? ? ? ||self.lineAfterParagraphSpacing >= 0
? ? ? ? ? ? ||self.lineBeforeParagraphSpacing >= 0)
? ? ? ? {
? ? ? ? ? ? NSMutableParagraphStyle * paragraph = [[NSMutableParagraphStyle alloc] init];
? ? ? ? ? ? if(self.lineRowSpacing>=0? ? ) {
? ? ? ? ? ? ? ? paragraph.lineSpacing=self.lineRowSpacing;
? ? ? ? ? ? }
? ? ? ? ? ? if (self.lineAfterParagraphSpacing >= 0) {
? ? ? ? ? ? ? ? paragraph.paragraphSpacing=self.lineAfterParagraphSpacing;
? ? ? ? ? ? }
? ? ? ? ? ? if (self.lineBeforeParagraphSpacing >= 0) {
? ? ? ? ? ? ? ? paragraph.paragraphSpacingBefore=self.lineBeforeParagraphSpacing;
? ? ? ? ? ? }
? ? ? ? ? ? [firstPartaddAttribute:NSParagraphStyleAttributeName
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? value:paragraph
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? range:NSMakeRange(0, firstPart.length)];
? ? ? ? }
? ? ? ? returnfirstPart;
? ? }
? ? @catch(NSException *exception) {
? ? ? ? returnfirstPart;
? ? }
}
//更新界面
-(void)reloadAttributeData
{
//? ? [self customAttributeAlignment:self.myAlignment];
? ? //? ? self.lineBreakMode = self.myLineBreakMode;
? ? //重新布局
? ? [self layoutAdaptiveLable];
}
#pragma mark 更新自適應(yīng)大小
- (void)layoutAdaptiveLable
{
? ? if (self.isAdjustWidthByHeight == NO && self.isAdjustHeightByWidth == NO) {
? ? ? ? return;
? ? }
//? ? self.numberOfLines = 0;
? ? CGRectnewFrame =self.frame;
? ? if (self.isAdjustHeightByWidth == YES) {? //高度自適應(yīng)
? ? ? ? CGFloat height = [self sizeThatFits:CGSizeMake(self.frame.size.width, MAXFLOAT)].height;
? ? ? ? newFrame.size.height= height;
? ? }else if (self.isAdjustWidthByHeight == YES){ //換掉自適應(yīng)
? ? ? ? CGFloat width = [self sizeThatFits:CGSizeMake(MAXFLOAT,self.frame.size.width)].width;
? ? ? ? newFrame.size.width= width;
? ? }
? ? self.frame= newFrame;
}
-(void)invocationAttributeBlock
{
? ? if (self.attributeBlock) {
? ? ? ? self.attributeBlock();
? ? ? ? if (self.isDestroyAttributeBlockAfterUse) {
? ? ? ? ? ? self.attributeBlock=nil;
? ? ? ? }
? ? }
}
//string中是否有color標(biāo)簽辽剧,myColor為nil送淆,不設(shè)置默認(rèn)顏色
//NO:表示有Color,不設(shè)置默認(rèn)顏色怕轿; YES偷崩,表示沒(méi)有color,可以設(shè)置默認(rèn)顏色
-(BOOL)isNotHaveColorInString:(NSString*)string
{
? ? if (self.myColor) { //myColor為nil撤卢,不設(shè)置默認(rèn)顏色
? ? ? ? NSRangerange = [stringrangeOfString:@"color"];
? ? ? ? if(range.location==NSNotFound) {
? ? ? ? ? ? returnYES;
? ? ? ? }
? ? }
? ? return NO;
}
#pragma mark myAttributedText
//重置富文本
-(void)setMyAttributedText:(NSAttributedString*)myAttributedText
{
? ? _myAttributedText= myAttributedText;
? ? self.attributedText= myAttributedText;
? ? [self reloadAttributeData];
}
#pragma mark 居中方式
//-(void)setMyAlignment:(MyCustomStrAlignment)myAlignment
//{
//? ? _myAlignment = myAlignment;
//? ? [self customAttributeAlignment:myAlignment];
//}
#pragma mark 字體大小
-(void)setMyFont:(UIFont*)myFont
{
? ? _myFont= myFont;
? ? if(myFont) {
? ? ? ? self.font= myFont;
? ? }
? ? //字體大小改變,界面布局也要變化
? ? [self layoutAdaptiveLable];
}
#pragma mark 顏色
-(void)setMyColor:(UIColor*)myColor
{
? ? _myColor= myColor;
? ? self.textColor= myColor;
}
#pragma mark 文字格式
//-(void)setMyLineBreakMode:(NSLineBreakMode)myLineBreakMode
//{
//? ? _myLineBreakMode = myLineBreakMode;
//? ? self.lineBreakMode = myLineBreakMode;
//}
#pragma mark *行間距 段前間距 段后間距
/*行間距**/
-(void)setLineRowSpacing:(CGFloat)lineRowSpacing
{
? ? _lineRowSpacing= lineRowSpacing;
}
/**段前間距**/
-(void)setLineBeforeParagraphSpacing:(CGFloat)lineBeforeParagraphSpacing
{
? ? _lineBeforeParagraphSpacing= lineBeforeParagraphSpacing;
}
/**段后間距**/
-(void)setLineAfterParagraphSpacing:(CGFloat)lineAfterParagraphSpacing
{
? ? _lineAfterParagraphSpacing= lineAfterParagraphSpacing;
}
#pragma mark 是否允許適配高度/寬度
/**固定寬度適配高度 默認(rèn) NO**/
-(void)setIsAdjustHeightByWidth:(BOOL)isAdaptiveHeightByWidth
{
? ? _isAdjustHeightByWidth= isAdaptiveHeightByWidth;
? ? if(isAdaptiveHeightByWidth) {
? ? ? ? _isAdjustWidthByHeight = NO;
? ? }
}
/**固定高度適配寬度 默認(rèn) NO**/
-(void)setIsAdjustWidthByHeight:(BOOL)isAdaptiveWidthByHeight
{
? ? _isAdjustWidthByHeight= isAdaptiveWidthByHeight;
? ? if(isAdaptiveWidthByHeight) {
? ? ? ? _isAdjustHeightByWidth = NO;
? ? }
}
#pragma mark - Public methods
//居中方式
//-(void)customAttributeAlignment:(MyCustomStrAlignment )myAlignment
//{
//? ? switch (myAlignment) {
//? ? ? ? case kMyTextAlignmentCenter:{
//? ? ? ? ? ? self.textAlignment = NSTextAlignmentCenter;
//? ? ? ? }
//? ? ? ? ? ? break;
//? ? ? ? case kMyTextAlignmentLeft:{
//? ? ? ? ? ? self.textAlignment = NSTextAlignmentLeft;
//? ? ? ? }
//? ? ? ? ? ? break;
//? ? ? ? case kMyTextAlignmentJustified:{
//? ? ? ? ? ? self.textAlignment = NSTextAlignmentJustified;
//? ? ? ? }
//? ? ? ? ? ? break;
//? ? ? ? case kMyTextAlignmentNatural:{
//? ? ? ? ? ? self.textAlignment = NSTextAlignmentNatural;
//? ? ? ? }
//? ? ? ? ? ? break;
//? ? ? ? case kMyTextAlignmentRight:
//? ? ? ? {
//? ? ? ? ? ? self.textAlignment = NSTextAlignmentRight;
//? ? ? ? }
//? ? ? ? ? ? break;
//? ? ? ? default:
//? ? ? ? ? ? break;
//? ? }
//? ?
//}
#pragma mark - Private methods
//將自定義MyCustomStrAlignment 換成 NSTextAlignment
//+(NSTextAlignment)changeCustomAlignment:(MyCustomStrAlignment)myAlignment
//{
//? ? NSTextAlignment align ;
//? ? switch (myAlignment) {
//? ? ? ? case kMyTextAlignmentCenter:{
//? ? ? ? ? ? align = NSTextAlignmentCenter;
//? ? ? ? }
//? ? ? ? ? ? break;
//? ? ? ? case kMyTextAlignmentLeft:{
//? ? ? ? ? ? align = NSTextAlignmentLeft;
//? ? ? ? }
//? ? ? ? ? ? break;
//? ? ? ? case kMyTextAlignmentJustified:{
//? ? ? ? ? ? align= NSTextAlignmentJustified;
//? ? ? ? }
//? ? ? ? ? ? break;
//? ? ? ? case kMyTextAlignmentNatural:{
//? ? ? ? ? ? align = NSTextAlignmentNatural;
//? ? ? ? }
//? ? ? ? ? ? break;
//? ? ? ? case kMyTextAlignmentRight:
//? ? ? ? {
//? ? ? ? ? ? align = NSTextAlignmentRight;
//? ? ? ? }
//? ? ? ? ? ? break;
//? ? ? ? default:{
//? ? ? ? ? ? align = NSTextAlignmentLeft;
//? ? ? ? }
//? ? ? ? ? ? break;
//? ? }
//? ? return align;
//}
//
////將NSTextAlignment 換成 自定義MyCustomStrAlignment
//+(MyCustomStrAlignment)changeTextAlignment:(NSTextAlignment)myAlignment
//{
//? ? MyCustomStrAlignment align ;
//? ? switch (myAlignment) {
//? ? ? ? case NSTextAlignmentCenter :{
//? ? ? ? ? ? align = kMyTextAlignmentCenter;
//? ? ? ? }
//? ? ? ? ? ? break;
//? ? ? ? case NSTextAlignmentLeft :{
//? ? ? ? ? ? align = kMyTextAlignmentLeft;
//? ? ? ? }
//? ? ? ? ? ? break;
//? ? ? ? case NSTextAlignmentJustified :{
//? ? ? ? ? ? align= kMyTextAlignmentJustified;
//? ? ? ? }
//? ? ? ? ? ? break;
//? ? ? ? case NSTextAlignmentNatural :{
//? ? ? ? ? ? align = kMyTextAlignmentNatural;
//? ? ? ? }
//? ? ? ? ? ? break;
//? ? ? ? case NSTextAlignmentRight :
//? ? ? ? {
//? ? ? ? ? ? align = kMyTextAlignmentRight;
//? ? ? ? }
//? ? ? ? ? ? break;
//? ? ? ? default:{
//? ? ? ? ? ? align = kMyTextAlignmentLeft;
//? ? ? ? }
//? ? ? ? ? ? break;
//? ? }
//? ? return align;
//}
#pragma mark? 將異常字符串處理成“”
//處理成空字符串
- (NSString*)dealEmptyMessageString:(NSString*)str
{
? ? str = [NSString stringWithFormat:@"%@",str];
? ? if ([self isMessageNullOrEmpty:str]) {
? ? ? ? return@"";
? ? }else{
? ? ? ? returnstr;
? ? }
}
//字符串是否為空
- (BOOL)isMessageNullOrEmpty:(NSString*)string
{
? ? if ([string isKindOfClass:[NSNull class]]) {
? ? ? ? returnYES;
? ? }
? ? string = [NSStringstringWithFormat:@"%@",string];
? ? returnstring ==nil|| string==(id)[NSNullnull] || [stringisEqualToString:@""] || string.length==0|| [stringisEqualToString:@"(null)"] || [stringisEqualToString:@"null"] || [stringisEqualToString:@"<null>"]|| [stringisEqualToString:@"0(NSNull)"];
}
@end
.h文件
#import <UIKit/UIKit.h>
//typedef enum {
//? ? kMyTextAlignmentLeft? ? ? = 0,
//? ? kMyTextAlignmentCenter? ? = 1,
//? ? kMyTextAlignmentRight? ? = 2,
//? ? kMyTextAlignmentJustified = 3,
//? ? kMyTextAlignmentNatural? = 4
//}MyCustomStrAlignment;
typedefvoid(^KZTCustomAttributeLabelBlock)(void);
@interfaceSTCustomTextView :UITextView
/**(不建議使用) 同步加載帶文本標(biāo)簽字符串 比較卡环凿,解決富文本無(wú)法準(zhǔn)確計(jì)算富文本視圖高度問(wèn)題
?*attributStr :標(biāo)簽文本,可設(shè)置文本居中方式放吩,自適應(yīng)文本視圖大小
?* 缺點(diǎn):*同步加載智听,比較卡,
?* 服務(wù)端配字體大小標(biāo)簽不可使用,字體大小只能客戶端寫(xiě)到推,不然顯示有問(wèn)題
?* 建議:不建議再使用這個(gè)屬性考赛, 建議使用asyncAttributStr屬性,異步)
?**/
@property (nonatomic,copy)NSString * attributStr;
/**(建議使用)異步處理帶文本標(biāo)簽* 解決富文本無(wú)法準(zhǔn)確計(jì)算富文本視圖高度問(wèn)題
?**優(yōu)點(diǎn): 異步加載標(biāo)簽文字莉测,界面比較流暢
?** 缺點(diǎn):同一個(gè)視圖多次賦值颜骤, 會(huì)出現(xiàn)文字重疊字體(顏色加重)的情況,(比如cell重用)
?**服務(wù)端配字體大小標(biāo)簽不可使用,字體大小只能客戶端寫(xiě)捣卤,不然顯示有問(wèn)題
?** 賦值后忍抽,由于是異步不能直接使用該視圖的frame布局,可在attributeBlock屬性的block回調(diào)中處理
?**建議:僅賦值一次或不會(huì)快速刷新多次的地方使用該屬性董朝,)鸠项,強(qiáng)烈建議使用異步,
?*/
@property(nonatomic,copy)NSString* asyncAttributStr;
/**
?字體大小,
?*/
@property (nonatomic, strong) UIFont? *myFont;//
/**
?對(duì)齊方式默認(rèn)居左 kMyTextAlignmentLeft
?*/
//@property (nonatomic, assign) MyCustomStrAlignment myAlignment;//
/**
?設(shè)置字體顏色子姜,如html標(biāo)簽中沒(méi)有
?返回的不是html語(yǔ)言的普通字符串設(shè)置顏色用的祟绊,設(shè)置過(guò)后原來(lái)的顏色就沒(méi)有用了
?*/
@property (nonatomic, strong) UIColor *myColor;
// default is NSLineBreakByTruncatingTail. used for single and multiple lines of text
@property(nonatomic)? ? ? ? NSLineBreakMode? ? myLineBreakMode;
/**行間距**/
@property (nonatomic,assign) CGFloat lineRowSpacing;
/**段后間距**/
@property(nonatomic,assign)CGFloatlineAfterParagraphSpacing;
/**段前間距**/
@property(nonatomic,assign)CGFloatlineBeforeParagraphSpacing;
/**NSAttributedString*
?* myAttributedText
?*/
@property(nonatomic,copy)NSAttributedString* myAttributedText;
/**
?isAdaptiveWidthByHeight
?isAdaptiveHeightByWidth
?不同時(shí)YES,其中一個(gè)為YES時(shí)哥捕,另一個(gè)會(huì)被改為NO牧抽,
?**/
/**固定高度適配寬度 默認(rèn) NO**/
@property (nonatomic,assign) BOOL isAdjustWidthByHeight;
/**固定寬度適配高度 默認(rèn) NO**/
@property (nonatomic,assign) BOOL isAdjustHeightByWidth;
/**異步展示加載asyncAttributStr后調(diào)用block*
?*注 目前僅在asyncAttributStr屬性后調(diào)用
?*注 使用時(shí)要預(yù)防block的循環(huán)引用,必要時(shí)要手動(dòng)打破循環(huán)引用
?*/
@property (nonatomic,copy)KZTCustomAttributeLabelBlock attributeBlock;
/**
?使用后是否將 KZTCustomAttributeLabelBlock 置nil,(手動(dòng)打破循環(huán)),使用時(shí)需先事先設(shè)置
?對(duì)asyncAttributStr屬性有效,
?默認(rèn) NO,block不置nil
?**/
@property(nonatomic,assign)BOOLisDestroyAttributeBlockAfterUse;
//將自定義MyCustomStrAlignment 換成 NSTextAlignment
//+(NSTextAlignment)changeCustomAlignment:(MyCustomStrAlignment)myAlignment;
////將NSTextAlignment 換成 自定義MyCustomStrAlignment
//+(MyCustomStrAlignment)changeTextAlignment:(NSTextAlignment)myAlignment;
@end