mirror of
https://github.com/wu736139669/ManagerDemo.git
synced 2026-08-05 05:55:42 +00:00
DTCoreText
This commit is contained in:
BIN
Binary file not shown.
@@ -19,6 +19,7 @@
|
|||||||
@property (weak, nonatomic) IBOutlet DTAttributedLabel *percentDtlabel;
|
@property (weak, nonatomic) IBOutlet DTAttributedLabel *percentDtlabel;
|
||||||
@property (weak, nonatomic) IBOutlet MRCircularProgressView *percentView;
|
@property (weak, nonatomic) IBOutlet MRCircularProgressView *percentView;
|
||||||
@property (weak, nonatomic) IBOutlet UILabel *typeLabel;
|
@property (weak, nonatomic) IBOutlet UILabel *typeLabel;
|
||||||
|
@property (weak, nonatomic) IBOutlet UIImageView *pieImage;
|
||||||
|
|
||||||
-(void)setInfoDic:(NSDictionary *)dic;
|
-(void)setInfoDic:(NSDictionary *)dic;
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -50,6 +50,11 @@
|
|||||||
NSDictionary* optionsDic = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:kCTTextAlignmentCenter],DTDefaultTextAlignment, nil];
|
NSDictionary* optionsDic = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:kCTTextAlignmentCenter],DTDefaultTextAlignment, nil];
|
||||||
NSAttributedString *percentString = [[NSAttributedString alloc] initWithHTMLData:data options:optionsDic documentAttributes:nil];
|
NSAttributedString *percentString = [[NSAttributedString alloc] initWithHTMLData:data options:optionsDic documentAttributes:nil];
|
||||||
_percentDtlabel.attributedString = percentString;
|
_percentDtlabel.attributedString = percentString;
|
||||||
|
CGRect frame = _percentDtlabel.frame;
|
||||||
|
CGSize size = [_percentDtlabel suggestedFrameSizeToFitEntireStringConstraintedToWidth:_percentDtlabel.frame.size.width];
|
||||||
|
frame.size.height = size.height+2;
|
||||||
|
_percentDtlabel.frame = frame;
|
||||||
|
_percentDtlabel.center = _pieImage.center;
|
||||||
[_percentView setProgress:percent/100.0 animated:NO];
|
[_percentView setProgress:percent/100.0 animated:NO];
|
||||||
}
|
}
|
||||||
-(void)setTimeWithString:(NSString*)htmlString
|
-(void)setTimeWithString:(NSString*)htmlString
|
||||||
@@ -84,11 +89,17 @@
|
|||||||
}else if([[dic objectForKey:@"state"] isEqualToString:@"EFFECTED"]){
|
}else if([[dic objectForKey:@"state"] isEqualToString:@"EFFECTED"]){
|
||||||
[self setTimeWithString:@"最近还款日"];
|
[self setTimeWithString:@"最近还款日"];
|
||||||
[_percentView setProgress:0 animated:NO];
|
[_percentView setProgress:0 animated:NO];
|
||||||
NSString* htmlStr = [dic objectForKey:@"descValue"];
|
NSString* htmlStr = [NSString stringWithFormat:@"<span style=\" text-align:center; \">%@</span> ",[dic objectForKey:@"descValue"]];
|
||||||
|
|
||||||
NSData *data = [htmlStr dataUsingEncoding:NSUTF8StringEncoding];
|
NSData *data = [htmlStr dataUsingEncoding:NSUTF8StringEncoding];
|
||||||
NSDictionary* optionsDic = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:kCTTextAlignmentCenter],DTDefaultTextAlignment, nil];
|
NSDictionary* optionsDic = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:kCTTextAlignmentCenter],DTDefaultTextAlignment, nil];
|
||||||
NSAttributedString *percentString = [[NSAttributedString alloc] initWithHTMLData:data options:optionsDic documentAttributes:nil];
|
NSAttributedString *percentString = [[NSAttributedString alloc] initWithHTMLData:data options:optionsDic documentAttributes:nil];
|
||||||
_percentDtlabel.attributedString = percentString;
|
_percentDtlabel.attributedString = percentString;
|
||||||
|
CGRect frame = _percentDtlabel.frame;
|
||||||
|
CGSize size = [_percentDtlabel suggestedFrameSizeToFitEntireStringConstraintedToWidth:60.0];
|
||||||
|
frame.size.height = size.height+2;
|
||||||
|
_percentDtlabel.frame = frame;
|
||||||
|
_percentDtlabel.center = _pieImage.center;
|
||||||
_priceLabel.text = [dic objectForKey:@"recRepayDate"];
|
_priceLabel.text = [dic objectForKey:@"recRepayDate"];
|
||||||
}else if ( [[dic objectForKey:@"state"] isEqualToString:@"ENABLED"])
|
}else if ( [[dic objectForKey:@"state"] isEqualToString:@"ENABLED"])
|
||||||
{
|
{
|
||||||
@@ -99,6 +110,11 @@
|
|||||||
NSDictionary* optionsDic = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:kCTTextAlignmentCenter],DTDefaultTextAlignment, nil];
|
NSDictionary* optionsDic = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:kCTTextAlignmentCenter],DTDefaultTextAlignment, nil];
|
||||||
NSAttributedString *percentString = [[NSAttributedString alloc] initWithHTMLData:data options:optionsDic documentAttributes:nil];
|
NSAttributedString *percentString = [[NSAttributedString alloc] initWithHTMLData:data options:optionsDic documentAttributes:nil];
|
||||||
_percentDtlabel.attributedString = percentString;
|
_percentDtlabel.attributedString = percentString;
|
||||||
|
CGRect frame = _percentDtlabel.frame;
|
||||||
|
CGSize size = [_percentDtlabel suggestedFrameSizeToFitEntireStringConstraintedToWidth:_percentDtlabel.frame.size.width];
|
||||||
|
frame.size.height = size.height;
|
||||||
|
_percentDtlabel.frame = frame;
|
||||||
|
_percentDtlabel.center = _pieImage.center;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@
|
|||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
</imageView>
|
</imageView>
|
||||||
<view contentMode="scaleToFill" id="jKx-eQ-tZj" customClass="DTAttributedLabel">
|
<view contentMode="scaleToFill" id="jKx-eQ-tZj" customClass="DTAttributedLabel">
|
||||||
<rect key="frame" x="16" y="28" width="38" height="28"/>
|
<rect key="frame" x="5" y="30" width="60" height="24"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
</view>
|
</view>
|
||||||
</subviews>
|
</subviews>
|
||||||
@@ -88,6 +88,7 @@
|
|||||||
<outlet property="nameLabel" destination="Idi-qw-ohG" id="Sin-dw-1XV"/>
|
<outlet property="nameLabel" destination="Idi-qw-ohG" id="Sin-dw-1XV"/>
|
||||||
<outlet property="percentDtlabel" destination="jKx-eQ-tZj" id="d0H-GV-ZdV"/>
|
<outlet property="percentDtlabel" destination="jKx-eQ-tZj" id="d0H-GV-ZdV"/>
|
||||||
<outlet property="percentView" destination="hV2-1G-Fem" id="GTM-2T-X7I"/>
|
<outlet property="percentView" destination="hV2-1G-Fem" id="GTM-2T-X7I"/>
|
||||||
|
<outlet property="pieImage" destination="oUp-Tx-bC8" id="iJY-QQ-NQv"/>
|
||||||
<outlet property="priceLabel" destination="gFc-RY-QUU" id="nSK-qF-A0n"/>
|
<outlet property="priceLabel" destination="gFc-RY-QUU" id="nSK-qF-A0n"/>
|
||||||
<outlet property="profitLabel" destination="gnS-Tv-BcD" id="fMT-gW-cxV"/>
|
<outlet property="profitLabel" destination="gnS-Tv-BcD" id="fMT-gW-cxV"/>
|
||||||
<outlet property="timeDtLabel" destination="0L4-K9-Tyn" id="5dK-d7-zP9"/>
|
<outlet property="timeDtLabel" destination="0L4-K9-Tyn" id="5dK-d7-zP9"/>
|
||||||
|
|||||||
+21
-1
@@ -639,6 +639,17 @@ static Class _layerClassToUseForDTAttributedTextContentView = nil;
|
|||||||
|
|
||||||
- (CGSize)suggestedFrameSizeToFitEntireStringConstraintedToWidth:(CGFloat)width
|
- (CGSize)suggestedFrameSizeToFitEntireStringConstraintedToWidth:(CGFloat)width
|
||||||
{
|
{
|
||||||
|
// // create a temporary frame, will be cached by the layouter for the given rect
|
||||||
|
// CGRect rect = [self _frameForLayoutFrameConstraintedToWidth:width];
|
||||||
|
// DTCoreTextLayoutFrame *tmpLayoutFrame = [self.layouter layoutFrameWithRect:rect range:NSMakeRange(0, 0)];
|
||||||
|
//
|
||||||
|
// // assign current layout frame properties to tmpLayoutFrame
|
||||||
|
// tmpLayoutFrame.numberOfLines = _numberOfLines;
|
||||||
|
// tmpLayoutFrame.lineBreakMode = _lineBreakMode;
|
||||||
|
// tmpLayoutFrame.truncationString = _truncationString;
|
||||||
|
//
|
||||||
|
// // we have a layout frame and from this we get the needed size
|
||||||
|
// return CGSizeMake(tmpLayoutFrame.frame.size.width + _edgeInsets.left + _edgeInsets.right, CGRectGetMaxY(tmpLayoutFrame.frame) + _edgeInsets.bottom);
|
||||||
// create a temporary frame, will be cached by the layouter for the given rect
|
// create a temporary frame, will be cached by the layouter for the given rect
|
||||||
CGRect rect = [self _frameForLayoutFrameConstraintedToWidth:width];
|
CGRect rect = [self _frameForLayoutFrameConstraintedToWidth:width];
|
||||||
DTCoreTextLayoutFrame *tmpLayoutFrame = [self.layouter layoutFrameWithRect:rect range:NSMakeRange(0, 0)];
|
DTCoreTextLayoutFrame *tmpLayoutFrame = [self.layouter layoutFrameWithRect:rect range:NSMakeRange(0, 0)];
|
||||||
@@ -648,8 +659,17 @@ static Class _layerClassToUseForDTAttributedTextContentView = nil;
|
|||||||
tmpLayoutFrame.lineBreakMode = _lineBreakMode;
|
tmpLayoutFrame.lineBreakMode = _lineBreakMode;
|
||||||
tmpLayoutFrame.truncationString = _truncationString;
|
tmpLayoutFrame.truncationString = _truncationString;
|
||||||
|
|
||||||
|
// Note: this returns an unreliable measure prior to 4.2 for very long documents
|
||||||
|
CGSize neededSize = CTFramesetterSuggestFrameSizeWithConstraints(self.layouter.framesetter, CFRangeMake(0, 0), NULL,
|
||||||
|
CGSizeMake(width, CGFLOAT_MAX),
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
// round up because generally we don't want non-integer view sizes
|
||||||
|
neededSize.width = ceilf(neededSize.width);
|
||||||
|
neededSize.height = ceilf(neededSize.height);
|
||||||
// we have a layout frame and from this we get the needed size
|
// we have a layout frame and from this we get the needed size
|
||||||
return CGSizeMake(tmpLayoutFrame.frame.size.width + _edgeInsets.left + _edgeInsets.right, CGRectGetMaxY(tmpLayoutFrame.frame) + _edgeInsets.bottom);
|
return CGSizeMake(neededSize.width + _edgeInsets.left + _edgeInsets.right, neededSize.height + _edgeInsets.bottom);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark Properties
|
#pragma mark Properties
|
||||||
|
|||||||
Reference in New Issue
Block a user