我在我的项目中使用了一个TTStyledTextLabel来解析超链接,一切都很好。我面临的唯一问题是,如果文本不适合TTStyledTextLabel的范围,就会截断一个很长的文本显示省略号。
换句话说,我需要与UILabel相同的行为,它添加省略号来指示某些文本被裁剪。我在TTStyledTextLabel和TTStyledText类中进行了搜索,没有提供实现这一点的条件。下面是我在UITableViewCell子类中用来适当设置TTStyledTextLabel框架的代码:
-(void) layoutSubviews
{
[super layoutSubviews];
.
.
.
CGSize maxSize = CGSizeMake(self.contentView.frame.size.width -TEXT_OFFSET_WIDTH, TT_TEXT_MAX_HEIGHT);
[[[self textLabelTTStyled] text] setWidth:maxSize.width];
[[self textLabelTTStyled] sizeToFit];
double heigthForTTLabel = [[[self textLabelTTStyled] text] height];
if (heigthForTTLabel > maxSize.height)
heigthForTTLabel = maxSize.height; // Do not exceed the maximum height for the TTStyledTextLabel.
**// The Text was supposed to clip here when maximum height is set!**
CGSize mTempSize = CGSizeMake([[[self textLabelTTStyled] text] width], heigthForTTLabel);
CGRect frame = CGRectMake(TEXT_OFFSET_X,TEXT_OFFSET_Y,mTempSize.width, mTempSize.height);
self.textLabelTTStyled.frame = frame;
.
.
.
}在tableView:cellForRowAtIndexPath:中,我在我的TTStyledTextLabel中设置了这样的文本
TTStyledText *styledStatusMessage = [TTStyledText textFromXHTML:@"This is a really long text, how long can this go on? This is a really long text, how long can this go on? This is a really long text, how long can this go on? This is a really long text, how long can this go on? This is a really long text, how long can this go on? This is a really long text, how long can this go on?"
lineBreaks:YES URLs:YES];
if (nil == styledStatusMessage) {
styledStatusMessage = [TTStyledText textWithURLs:[statusMessage title] lineBreaks:YES];
[[cell textLabelTTStyled] setText:styledStatusMessage];
}多余的文本将被丢弃,默认情况下不会添加省略号来指示文本已被裁剪。这个问题有什么解决方案吗?
谢谢,Raj
发布于 2011-10-12 14:54:54
我相信你正在使用一个私有的Three20接口,它有机会在你上传之前被appstore.Just检查拒绝。一般你可以设置任何设置任何自定义按钮上的设置标题
button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft;按钮setTitleEdgeInsets:UIEdgeInsetsMake(0.0,10.0,0.0,0.0);-此行可用于设置标题边。希望能有所帮助。
https://stackoverflow.com/questions/3656395
复制相似问题