English 中文(简体)
改写 2. 装配单元 B. 牢房外的观点
原标题:Changing UITableViewCell width to fit a UIImageView outside of the cell

我愿了解摆脱布局的最佳方式/方法? 我想把UITableViewCell外的UIImage号电文放在一个带有固定细胞的UITableView上。

Screenshot of what i m trying to achieve

我采取了以下做法:在第1节用以下代码对牢房进行电离电灯分类。

- (void)setFrame:(CGRect)frame {
    frame.size.width -= 125.0;
    [super setFrame:frame];
}

In the UITableViewController s viewDidLoad 我根据惯例UITableViewCell的宽度补充了该词。

This sort of works, but i m not sure how to deal with rotation and also if what i ve done so far would be the correct way?

最佳回答

我设法得出了我所希望的以下内容,这显然不是最佳方式,也不是最清洁的方法,而是因为没有一位来自斯克拉奥弗洛的人提出任何更好的建议,我认为我对此作了更好的回答。

I subclassed the first 3 UITableViewCells and set a frame size to take into account the size of my image.

- (void)setFrame:(CGRect)frame {
float cellWidth = (frame.size.width - 345);
frame.size.width = cellWidth;

[super setFrame:frame];

}

随后,我用可调的电文对Load 我在表格中用第一个固定单元制作并定位UIImageView,作为IBOutlet(“第一Cell”)。 然后,我确定“马什克”的自动恢复,从而打破了轮换,最后添加“UIImage”的意见。

//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];

landscape portrait

这还没有经过充分测试,而且一毫肯定不会得到很大的执行,而是它的一个起点。 如果你知道有更好的办法,请作出答复。

注:上述代码是供我阅读的iPad的,但从I.M.的测试中抽取。

问题回答

这样做的方法各不相同。 一种办法是降低表层的宽度,因为你在表2中显示的是使用定制表视器和必要的电池添加图像,以便显示你的细胞数据和图像。 i 认为习俗小组是更好的解决办法。 请告诉我,如果你问一问,我回答的是什么,如果没有的话,那么我会审查我的回答。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签