Iphone 如何在tableview手机中设置textLabel的位置 在我的表视图中,我使用的是UITableviewCEllStyleValue1:
这里显示两个标签文本标签,detailTextLabelIphone 如何在tableview手机中设置textLabel的位置 在我的表视图中,我使用的是UITableviewCEllStyleValue1:,iphone,objective-c,xcode,uitableview,Iphone,Objective C,Xcode,Uitableview,这里显示两个标签文本标签,detailTextLabel 但不是我想要的位置 我需要从单元格的起始位置(0,0)显示Textlable,Immidate右侧位置为detailTextlabel两个标签之间没有间隙 我需要一个不使用Allignment的解决方案。怎么办 创建一个自定义UITableViewCell子类并重写layoutSubviews方法。您必须为此创建自定义单元格。像这样, 在CustomCellTableViewCell.h文件中 如果使用initWithStyle:UITa
创建一个自定义
UITableViewCell
子类并重写layoutSubviews
方法。您必须为此创建自定义单元格。像这样,
在CustomCellTableViewCell.h文件中
如果使用initWithStyle:UITableViewCellStyleDefault,则NSTextAlignmentCenter可以工作。默认的cell.textlabel不可移动这到底是怎么回事。。!!我被提到了那个自定义单元格,那为什么不投票呢?
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.text = @"Hai";
cell.detailTextLabel.text = @"Hello";
cell.detailTextLabel.textAlignment = UITextAlignmentLeft;
cell.textLabel.textAlignment = UITextAlignmentLeft;
return cell;
}
#import <UIKit/UIKit.h>
@interface CustomCellTableViewCell : UITableViewCell
@property(nonatomic,strong)UILabel *lblUnit;
@end
in CustomCellTableViewCell.m file
#import "CustomCellTableViewCell.h"
@implementation CustomCellTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
self.userInteractionEnabled = YES;
if (self) {
// Initialization code
self.lblUnit = [[UILabel alloc]init];
[self.lblUnit setTextColor:[UIColor whiteColor]];
[self.lblUnit setFont:[UIFont fontWithName:@"Roboto-Light" size:30.0f]];
// [self.lblUnit setFont:[UIFont systemFontOfSize:18.0]];
self.lblUnit.textAlignment = UIBaselineAdjustmentAlignCenters;
self.lblUnit.adjustsFontSizeToFitWidth = YES;
[self.contentView addSubview:self.lblUnit];
}
return self;
}
@end
in your Tableview CellForRowAtIndexpath write below code
cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if(cell==nil){
cell = [[CustomCellTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
cell.lblUnit.frame = CGRectMake(0, 10, 150, 40);
cell.lblUnit.text = @"Hai";
return cell;