更改UITableViewCell宽度以适应单元格外的UIImageView
我想知道从以下布局实现的最佳方式/正确方法? 我想在UITableView的UITableViewCell之外放置一个UIImageView与静态单元格。
我已经做了以下通过inheritanceUITableViewCell为第1节中的单元格使用下面的代码
- (void)setFrame:(CGRect)frame { frame.size.width -= 125.0; [super setFrame:frame]; }
在UITableViewController的viewDidLoad中,我添加了UIImageView,并根据自定义的UITableViewCell的宽度来定位它。
这样的作品,但我不知道如何处理旋转,以及如果我迄今为止做的将是正确的方式?
有不同的方法来做到这一点。 一个是设置表格视图的宽度减less,因为你在图片中显示第二是使用自定义表格视图单元格和所需的单元格添加图像,以便您的单元格数据以及图像将显示。 我认为定制单元会是更好的解决scheme。 告诉我,如果你问同样的事情,我回答,如果没有,那么我检讨我的答案谢谢。
我设法产生我想要的使用后续,这是proberly不是最好的方式或最干净的方式,但没有人从StackOverFlow给出了更好的build议,我想我最好回答这个问题。
我subclassed前3 UITableViewCells并设置一个帧大小考虑到我的形象的大小。
- (void)setFrame:(CGRect)frame { float cellWidth = (frame.size.width - 345); frame.size.width = cellWidth; [super setFrame:frame];
}
然后在我的UITableViewController的viewDidLoad我创build和定位UIImageView作为IBOutlet(“firstCell”)使用tableview中的第一个静态单元格。 然后我设置autoResizingMask,它将旋转sorting并最终将UIImageView添加到视图。
//Create and position the image view UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((firstCell.frame.size.width), (firstCell.frame.origin.y + 70), 300, 137)]; // Add border and round corners of image view to make style look a little like tableviewcells [imageView.layer setBorderColor:[UIColor colorWithWhite:0 alpha:0.5].CGColor]; [imageView.layer setBorderWidth:2.0]; [imageView.layer setCornerRadius:5.0]; [imageView setClipsToBounds:YES]; //Set the image in the image view UIImage *image = [UIImage imageNamed:@"defaultPicture.png"]; imageView.image = image; //Set resizing of image view for when view is rotated imageView.contentMode = UIViewContentModeRedraw; imageView.autoresizingMask = UIViewContentModeScaleAspectFit; //Add tap gesture for imageview to initiate taking picture. imageView.userInteractionEnabled = YES; UITapGestureRecognizer *imageViewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(takePicture:)]; [imageView addGestureRecognizer:imageViewTap]; //Add image view to view [self.view addSubview:imageView];
这还没有经过充分testing,我敢肯定,这不是一个很好的实现,但它是我后来的效果的起点。 如果您知道更好的方法,请回复。
注意:上面的代码是在iPad上为我的应用程序编写的,但截图来自我在iPhone上进行的testing
- 使用updateApplicationContext发送keychain值是否安全
- MFMessageComposeViewController未正确显示
- 通过单击表视图中的单元格打开新的视图控制器 – Swift iOS
- 在开发过程中testingCloudKit中的NSUserDeletedZone
- Xcode是自动添加信息图标/“附件button”我的表格单元格
- iOS:使用TouchID进行身份验证
- 来自UITableView的deleteRowsAtIndexPaths的不规则animation:withRowAnimation:
- 从MKMapView中找出您所在的区域
- iPhone应用程序生命周期中的最后一个function是什么?