CustomCell 自适应高度
//Customiz the height of table view cell
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
Status * sts = [statuses objectAtIndex:indexPath.row];
NSString *cellText = sts.text;
UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:17.0];
CGSize constraintSize = CGSizeMake(240.0f, MAXFLOAT);
CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
return labelSize.height + 20;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
//cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
// cell.textLabel.numberOfLines = 0;
//cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:17.0];
}
Status *sts = [statuses objectAtIndex:indexPath.row];
//cell.textLabel.text = sts.user.screenName;
//cell.detailTextLabel.text = sts.text;
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(80, 0, 240, 20)];
label.text = sts.user.screenName;
[cell addSubview:label];
[label release];
NSString *cellText = sts.text;
UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:12.0];
CGSize constraintSize = CGSizeMake(240.0f, MAXFLOAT);
CGSize labelHeight = [cellText sizeWithFont:cellFont];
CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
UILabel* tv = [[UILabel alloc]initWithFrame:CGRectMake(80, 20, labelSize.width, labelSize.height)];
tv.text = sts.text;
tv.textColor = [UIColor yellowColor];
tv.numberOfLines = ceil(labelSize.height/labelHeight.height);
tv.lineBreakMode = UILineBreakModeWordWrap;
tv.backgroundColor = [UIColor grayColor];
//[label sizeToFit];
[cell addSubview:tv];
[tv release];
// Configure the cell.
return cell;
}
UILabel 自动换行
CGSizetitleBrandSizeForHeight = [titleBrand.textsizeWithFont:titleBrand.font];
CGSizetitleBrandSizeForLines = [titleBrand.textsizeWithFont:titleBrand.fontconstrainedToSize:CGSizeMake(infoWidth,MAXFLOAT)lineBreakMode:UILineBreakModeWordWrap];
titleBrand.numberOfLines=ceil(titleBrandSizeForLines.height/titleBrandSizeForHeight.height);
if(titleBrand.numberOfLines<=1)
{
titleBrand.frame=CGRectMake(5,titleBrand.frame.size.height,
infoWidth, titleBrandSizeForHeight.height);
}else{
titleBrand.frame=CGRectMake(5,titleBrand.frame.size.height,
infoWidth,titleBrand.numberOfLines*titleBrandSizeForHeight.height);
}
UITextView根据内容自动调整高度
- (void)textViewDidChange:(UITextView*)textView{
if(textView.text.length> 20)//一行最多多少字节
{
<wbr><wbr><wbr><wbr><wbr>//TextView底面背景图片根据内容自动调整高度</wbr></wbr></wbr></wbr></wbr>
UIImage*img = [UIImageimageWithContentsOfFile:[[NSBundlemainBundle]pathForResource:@"inputbox"ofType:@"png"]];
[BgImagesetImage:[imgstretchableImageWithLeft<wbr>CapWidth<span style="color:rgb(0,0,0)">:</span><span style="color:rgb(62,1,216)">21</span>topCapHeight<span style="color:rgb(0,0,0)">:</span><span style="color:rgb(62,1,216)">14</span><span style="color:rgb(0,0,0)">]];</span></wbr>
UIFont*font = [UIFontsystemFontOfSize:12];
CGSizesize = [textView.textsizeWithFont:fontconstrainedToSize:CGSizeMake(320,140)lineBreakMode:UILineBreakModeWordWrap];
BgImage.frame=CGRectMake(0,202-size.height+15,320,
size.height+28);
InputTextVeiw.contentInset=UIEdgeInsetsZero;//以换行为基准
[textViewsetFrame:CGRectMake(51,210-size.height+18,200,
size.height+5)];
}
}
相关推荐
UILabel ios7 与ios7之前实现自适应撑高的方法, 文本的内容长度不一,需要根据内容的多少来自动换行处理文本的内容。这里简单实现ios7自适应撑高的方法.
github地址:https://github.com/fengzhihao123/UI-Swift 如果帮助到了大家,还望点个star和fork
UILabel 自动换行的demo,修改代码中的文字就可以自动适应
可以根据需要不同来选择使用高度自适应和宽度自适应.
UIlabel根据文本、字体获得label宽度;自适应宽高
swift学习控件篇:UIButton+UILabel
利用UISrollView+UILabel 的方法实现表格的制作,实现的功能有: 1)以表格单元的形式显示数据; 2)可以左右、上下滑动表格。 适合IOS初学者。
IOS 中UITextField,UITextView,UILabel 根据内容来计算高度 在开发的过程中,常常遇到根据内容来决定控件的高度的情况,常见的就是UITextField,UITextView,UILabel这三个控件,下面一UITextView 为例来说明一下: ...
UIlabel根据文本、字体获得label宽度;自适应宽高
标题已经写明,例子代码里有,用法可以customlabel.verticalAlignment=CustomLabel.VerticalAlignment.VerticalAlignmentBottom底部对齐
博客中的IOS TableView的Cell高度自适应,UILabel自动换行适应 的项目源码
下面小编就为大家带来一篇iOS 设置UILabel的行间距并自适应高度的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
主要为大家详细介绍了iOS UILabel根据内容自动调整高度,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
3、支持UILabel,UIButton,UITextField,UITextView类以及自定义的继承类。 4、支持某些类和某个对象不适配。 5、关闭某个对象适配,支持手动代码和storyboard两种设置。 6、支持不分屏幕尺寸,统一修改字体大小。 ...
本Demo是在继承UIControl的基础上,绘制出一个类似UILabel 的控件,可以实现文字的显示,文字颜色、大小的设置。
比较方便的多行UILabel 可自定义文字间距,行间距,及段落间距 有这方面需求的可以下来用用,直接导入.h .m文件即可 .h里有使用方法
简介 UILabel类实现了一个只读文本视图。您可以使用这个类来画一个或多个行静态文本,比如你可能使用确定的其他部分的用户界面。...有时我们需要根据UILabel内部的字体格式(包括字体大小,行间距)来动态调整
简单方便的给UILabel内容中某几个文字添加点击事件,实现定制要求