DTCoreText

This commit is contained in:
2014-09-09 11:56:34 +08:00
parent 795aaaa055
commit dc493126c7
5 changed files with 42 additions and 4 deletions
@@ -19,6 +19,7 @@
@property (weak, nonatomic) IBOutlet DTAttributedLabel *percentDtlabel;
@property (weak, nonatomic) IBOutlet MRCircularProgressView *percentView;
@property (weak, nonatomic) IBOutlet UILabel *typeLabel;
@property (weak, nonatomic) IBOutlet UIImageView *pieImage;
-(void)setInfoDic:(NSDictionary *)dic;
@end
+17 -1
View File
@@ -50,6 +50,11 @@
NSDictionary* optionsDic = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:kCTTextAlignmentCenter],DTDefaultTextAlignment, nil];
NSAttributedString *percentString = [[NSAttributedString alloc] initWithHTMLData:data options:optionsDic documentAttributes:nil];
_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];
}
-(void)setTimeWithString:(NSString*)htmlString
@@ -84,11 +89,17 @@
}else if([[dic objectForKey:@"state"] isEqualToString:@"EFFECTED"]){
[self setTimeWithString:@"最近还款日"];
[_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];
NSDictionary* optionsDic = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:kCTTextAlignmentCenter],DTDefaultTextAlignment, nil];
NSAttributedString *percentString = [[NSAttributedString alloc] initWithHTMLData:data options:optionsDic documentAttributes:nil];
_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"];
}else if ( [[dic objectForKey:@"state"] isEqualToString:@"ENABLED"])
{
@@ -99,6 +110,11 @@
NSDictionary* optionsDic = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:kCTTextAlignmentCenter],DTDefaultTextAlignment, nil];
NSAttributedString *percentString = [[NSAttributedString alloc] initWithHTMLData:data options:optionsDic documentAttributes:nil];
_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"/>
</imageView>
<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"/>
</view>
</subviews>
@@ -88,6 +88,7 @@
<outlet property="nameLabel" destination="Idi-qw-ohG" id="Sin-dw-1XV"/>
<outlet property="percentDtlabel" destination="jKx-eQ-tZj" id="d0H-GV-ZdV"/>
<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="profitLabel" destination="gnS-Tv-BcD" id="fMT-gW-cxV"/>
<outlet property="timeDtLabel" destination="0L4-K9-Tyn" id="5dK-d7-zP9"/>
+22 -2
View File
@@ -639,7 +639,18 @@ static Class _layerClassToUseForDTAttributedTextContentView = nil;
- (CGSize)suggestedFrameSizeToFitEntireStringConstraintedToWidth:(CGFloat)width
{
// 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];
// 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
CGRect rect = [self _frameForLayoutFrameConstraintedToWidth:width];
DTCoreTextLayoutFrame *tmpLayoutFrame = [self.layouter layoutFrameWithRect:rect range:NSMakeRange(0, 0)];
@@ -648,8 +659,17 @@ static Class _layerClassToUseForDTAttributedTextContentView = nil;
tmpLayoutFrame.lineBreakMode = _lineBreakMode;
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
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