English 中文(简体)
UITableview, 垂直中心是具有动态高度的电池的物体?
原标题:UITableview, vertically center a object of a cell with dynamic height?

我有一些可调用的电文,是动态的,有些其他物体应纵向集中。

此时此刻,我计算了UITextView的高度,并把它用作确定一切的参考。

问题一是,有时它计算出错误和“价格”总是在中上端? 上诉人,如发卷的20%,因此,牢房将再次站起来。

Is there a way to get the higeht of the cell? And why does it calculate wrong? It also cuts the UITextView in half when this problem appear?

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    CGSize size;
    NSString *text;
    /* Height of each cell */
     text = @"Some different lengths of text";
     size = [text sizeWithFont:[UIFont fontWithName:@"TrebuchetMS" size:17] constrainedToSize:CGSizeMake(theTableView.bounds.size.width - 260, 800) lineBreakMode:UILineBreakModeWordWrap];

     float totalSize = size.height + 10;
     if (totalSize < 120) {
          return 120;
     } else {
         return totalSize;
     }
}


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

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {

        CGSize size;
        NSString *text;
        float totalSize;
        /* Height of each cell */
        text = @"Some different lengths of text";
        size = [text sizeWithFont:[UIFont fontWithName:@"TrebuchetMS" size:17] constrainedToSize:CGSizeMake(theTableView.bounds.size.width - 260, 800) lineBreakMode:UILineBreakModeWordWrap];
            if (size.height + 10 < 120) {
                totalSize = 120;
            } else {
                totalSize = size.height + 10;
            }
        }

        /* Createing a new Cell */
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

        /* Create the text Label */
        textView = [[[UITextView alloc] initWithFrame: CGRectMake(90,35,theTableView.bounds.size.width - 260 , totalSize)] autorelease];
        [cell.contentView addSubview:textView];
        textView.tag = TEXT_LABEL_TAG;
        textView.backgroundColor = [UIColor clearColor];
        textView.textColor = [UIColor blackColor];
        textView.font = [UIFont fontWithName:@"TrebuchetMS" size:17];
        textView.editable = NO;
        textView.userInteractionEnabled = NO;

        /* Create price Label */
        priceLabel = [[[UILabel alloc] initWithFrame: CGRectMake(theTableView.bounds.size.width - 225, (totalSize/2) - (35/2), 120 , 35)] autorelease];
        [cell.contentView addSubview:priceLabel];
        priceLabel.tag = PRICE_LABEL_TAG;
        priceLabel.textAlignment = UITextAlignmentRight;
        priceLabel.backgroundColor = [UIColor clearColor];
        priceLabel.textColor = [UIColor redColor];
        priceLabel.font = [UIFont fontWithName:@"TrebuchetMS-Bold" size:22];
问题回答

在我确定次调查框架及其立场时,我有两.,与你在座右铭:电话中所做的那样。 在转型期间,框架似乎很强。 在进行次目测后,我先发现有更好的uck子和中心特性。 这可能会使你更好地控制中心。

label.bounds = CGRectMake(0,0,0.6*self.view.frame.size.width,30);
label.center = CGPointMake(0.5*self.view.frame.size.width, 0.23*self.view.bounds.size.height);

除座标有星数外,你的代码看重罚款。 因此,试图使用

priceLabel = [[[UILabel alloc] initWithFrame: CGRectMake(theTableView.bounds.size.width - 225, (totalSize/2.f) - (35.f/2.f), 120 , 35)] autorelease];

它可以提供帮助,但不能肯定。





相关问题
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, ...

热门标签