私のやり方がTTTAttributedLabelでCKを組み合わせることであるあなたの目標を達成することができます。
+ (instancetype)newWithData:(ABCKAttributeLabelData)data {
ABCKAttributeLabelComponent *com =
[super newWithView:{
[TTTAttributedLabel class],
{
{@selector(setText:), [data.content attributedStringWithStyle:
@{NSForegroundColorAttributeName : data.normalColor,
NSFontAttributeName : data.normalFont,}]},
{@selector(setLinkAttributes:), @{ NSForegroundColorAttributeName : data.linkColor,
NSFontAttributeName : data.linkFont}},
{@selector(setActiveLinkAttributes:), @{ NSForegroundColorAttributeName : data.linkColor,
NSFontAttributeName : data.linkFont}},
{@selector(setNumberOfLines:), data.numberOfLines ?: 0},
{@selector(setLineBreakMode:), NSLineBreakByTruncatingTail},
}
} size:{}];
com.attributeString = [data.content attributedStringWithStyle:
@{NSForegroundColorAttributeName : data.normalColor,
NSFontAttributeName : data.normalFont,}];
com.normalFont = data.normalFont;
com.numOfLine = data.numberOfLines ?: 0;
return com
:まず、私は以下のようにCKComponentのABCKAttributeLabelComponentサブクラスという名前の新しいクラス、実装initializeメソッドを作成し、その後
struct ABCKAttributeLabelData {
NSString *content;
UIFont *normalFont;
UIColor *normalColor;
UIFont *linkFont;
UIColor *linkColor;
NSInteger numberOfLines;
};
、それは私がTTTAttributedLabelに設定する必要がありますいくつかの基本的な情報が含まれている、構造体を定義します
第3に、TTTAttributedLabelのサイズを計算して返します。 CKはcomputeLayoutThatFits:メソッドを呼び出してコンポーネントのサイズを取得します。だからそれを上書きしてください。
- (CKComponentLayout)computeLayoutThatFits:(CKSizeRange)constrainedSize {
// self.attributeString,self.numOfLine and self.normalFont I saved as property in initialize method
CGSize computerSize = [self.attributeString sizeLabelToFitToSize:constrainedSize.max numberLines:self.numOfLine font:self.normalFont];
return {
self,
constrainedSize.clamp({
CKCeilPixelValue(computerSize.width),
CKCeilPixelValue(computerSize.height)
}),
{}
};
}
物事の残りの部分はABCKAttributeLabelComponentを使用することです。
非常に優雅ではないかもしれませんが、動作します。
出典
2017-08-08 16:03:49
YUI
あなたはそれについて解決策を見つけましたか? – lee
いいえ。彼らはよくサポートしていないし、私はそれを使用してあきらめます。彼らは将来的にはより多くの支持を得ることを願っています。 –