gpt4 book ai didi

ios - 在 uiScrollView 之前添加 uiTextView

转载 作者:行者123 更新时间:2023-11-29 04:03:50 25 4
gpt4 key购买 nike

我希望 TextView 位于表格单元内的 ScrollView 之前,如下所示,以便 ScrollView 滚动并且标题保持不变。

[Title goes here] - it does not move with the scrollview
---------------------
| |
| ScrollView |
| |
---------------------

这是我的代码,textView出现在 ScrollView 后面。

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"];

if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MainCell"];
}

NSInteger numberOfViews = 10;
UIScrollView *vwScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 1280, 200)];

for (int i = 0; i < numberOfViews; i++) {
CGFloat xOrigin = i * 250;
UITextView *titleView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 1280, 20)];
titleView.text = @"Title";
[titleView setFont:[UIFont fontWithName:@"HelveticaBold" size:32]];


UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(xOrigin, 0, 250, 180)];
awesomeView.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5/i/10 blue:0.5 alpha:1];
[awesomeView.layer setBorderColor:[UIColor whiteColor].CGColor];
[awesomeView.layer setBorderWidth:10.5f];
awesomeView.layer.shadowPath = [UIBezierPath bezierPathWithRect:awesomeView.bounds].CGPath;

[cell.contentView addSubview:titleView];
[vwScroll addSubview:awesomeView];

}
vwScroll.contentSize = CGSizeMake(250 * numberOfViews, 200);

[cell.contentView addSubview:vwScroll];

return cell;
}

最佳答案

为什么不能将 titleView 的框架设置为 (0,0,width,titleHeight) ,然后将 scrollView 的框架设置为 (0,titleHeight,宽度,单元格高度-标题高度)

这只会将标题放置在单元格的顶部,将其高度设置为您设置的 titleHeight 的高度,并将 ScrollView 放置在单元格的底部,将其设置为到单元格其余部分的高度。

关于ios - 在 uiScrollView 之前添加 uiTextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15493964/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com