简体   繁体   中英

UIScrollView Inside UITableViewCell

I'm trying to add a UIScrollView inside my TableViewCell. It appears to be going well, however when the label comes in from the right as I'm scrolling, it comes in above the cell, but as the text moves to the left edge of the label, it disappears behind the label like I want it to.

Any suggestions?

UIScrollView *previewScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, cell.contentView.frame.size.width, 80.0)];
        previewScrollView.backgroundColor = [UIColor clearColor];
        [previewScrollView setContentSize:CGSizeMake(500, 60.0)];
        previewScrollView.showsHorizontalScrollIndicator = YES;

        UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(15.0, 3.0, 500.0, 20.0)];
        headerLabel.font = [UIFont boldSystemFontOfSize:14.0];
        headerLabel.backgroundColor = [UIColor clearColor];
        headerLabel.text = @"My long text string that I hope work out ok";
        [previewScrollView addSubview:headerLabel];

        [[cell contentView] addSubview:previewScrollView];        
        //[cell addSubview:previewScrollView];
        [previewScrollView release];

from the right as I'm scrolling, it comes in above the cell

Above the cell as in y or z axis?

If it is above in the y axis, you could try setting clipsToBounds on the scroll view. That makes it so subviews are only drawn within the area of their superview.

If it is above in the z axis, where something in front should be behind, try using:

[[cell contentView] insertSubview:previewScrollView atIndex:0];

inserting at index 0 ensures a view is behind all other subviews in the superview.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM