我曾尝试使用内容大小调整单元格大小,但我了解到在 IOS 8 中您可以使用自动版式调整单元格大小。我尝试了同样的方法,但无法获得确切的用户界面。我在 UIView Controller 中有一个 TableView。这是我的代码 viewcontroller.m :-
@implementation MessageViewController
@synthesize messageTable;
- (void)viewDidLoad {
self.messageTable.estimatedRowHeight = 70.0;
self.messageTable.rowHeight = UITableViewAutomaticDimension;
[super viewDidLoad];
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
self.navigationController.toolbarHidden=NO;
_txtField=[[UITextView alloc] initWithFrame:CGRectMake(40, 5, 220, 30)];
[_txtField setFont:[UIFont systemFontOfSize:15]];
_txtField.layer.cornerRadius = 7.0;
_txtField.clipsToBounds = YES;
_txtField.text=@"Hello";
[self.navigationController.toolbar addSubview:_txtField];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"Send" forState:UIControlStateNormal];
button.frame = CGRectMake(265.0, 5, 50.0, 30.0);
[self.navigationController.toolbar addSubview:button];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
// table view data is being set here
_messageArray = [[NSMutableArray alloc]initWithObjects:
@"Data 2 ",@"Data 1 Data 1Data 1Data 1Data 1Data 1Data 1Data 1Data 1D",@"Data 8 ",
@"Data 9 ", nil];
[self.messageTable reloadData];
// Do any additional setup after loading the view.
}
UI 看起来像这样:-
标签上的约束是:-
需要帮助:)
编辑:-
单元格
最佳答案
http://www.appcoda.com/self-sizing-cells/ 您可以尝试此链接以仅在 iOS 8 中自动调整标签大小。
并且不要忘记在您的 viewdidload 中添加以下行。
tableView.estimatedRowHeight = 44.0
tableView.rowHeight = UITableViewAutomaticDimension
关于ios - 在 IOS 8 中使用自动布局调整单元格大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28347001/