我下載了Collection View example,我用文本字段替換了ImageView。 我想使文本字段與UICollectionViewCell一樣大(這是一個正方形形狀)。但是textfield的形狀沒有改變。如何製作一個與UICollectionViewCell一樣大的文本字段?
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
// height and width in the parent cell
double height = cell.frame.size.height;
double width = cell.frame.size.width;
// get the child textfield
UITextField *textField = (UITextField *)[cell viewWithTag:100];
// make the textfield as big as the cell
CGRect frame = CGRectMake(0, 0, width, height);
textField.frame =frame;
textField.text = @"testing";
return cell;
}
嘗試使用一個TextView來代替。 – AMayes 2013-03-15 17:00:51