我有一个由代码制作的 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 实施。
编辑:
表视图代码:
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;
}