gpt4 book ai didi

iphone - 从纵向更改为横向时如何调整单元格中的 UITextView 的大小?

转载 作者:行者123 更新时间:2023-11-29 11:03:25 25 4
gpt4 key购买 nike

我有一个用代码制作的 TextView。

CGRect textFrame = CGRectMake(5, 20, 300, 50);

UITextView *textView = [[UITextView alloc] initWithFrame:textFrame];

问题是,我想在调用横向模式时调整它的大小。

这里有一些例子:

https://docs.google.com/file/d/0BzsX_FHtJa9nSjRVamtFX1pjdlE/edit?usp=sharing

https://docs.google.com/file/d/0BzsX_FHtJa9nU0U5T3JvZkgzZWc/edit?usp=sharing

谢谢

PS:这仅适用于 iPhone。没有 iPad 实现。

编辑:

表格 View 代码:

tableProducts.dataSource = self;
tableProducts.delegate = self;
tableProducts.bounces = YES;

单元格代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableProducts dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}

/* ------ Product title in RED ------*/

CGRect titleFrame = CGRectMake(5, 5, 250, 15);
UILabel *productTitle = [[UILabel alloc] initWithFrame:titleFrame];
productTitle.font = [UIFont boldSystemFontOfSize:14];
productTitle.textColor = [UIColor redColor];
productTitle.text = [listProducts objectAtIndex:indexPath.row];

[cell.contentView addSubview:productTitle];

/* ------ Product title in RED ------*/

/* ------ Product Text ------*/

CGRect textFrame = CGRectMake(5, 20, 300, 50);
UITextView *textView = [[UITextView alloc] initWithFrame:textFrame];
textView.textColor = [UIColor blackColor];
textView.font = [UIFont boldSystemFontOfSize:11.5];
textView.text = [listTexts objectAtIndex:indexPath.row];
textView.scrollEnabled = NO;
textView.editable = NO;

[cell.contentView addSubview:textView];

/* ------ Product Text ------*/

return cell;
}

最佳答案

设置文本的自动调整大小

 textview.autoresizingMask = UIViewAutoresizingFlexibleWidth;

关于iphone - 从纵向更改为横向时如何调整单元格中的 UITextView 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14762090/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com