這段代碼演示瞭如何將滾動視圖添加到單元格和完美的作品,但我想加載這是我設計的廈門國際銀行和作爲尋呼啓用滾動視圖,我試圖直接加載滾動視圖的內容查看到細胞,但它合乎理水平顯示正確和犯規滾動它確實在tableview中細胞外,請指導我會需要什麼樣的變化的UIScrollView裏面一個UITableViewCell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"ScrollCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
UIScrollView *scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 25, 320, 25)];
scroller.showsHorizontalScrollIndicator = NO;
UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320*4, 25)];
contentLabel.backgroundColor = [UIColor blackColor];
contentLabel.textColor = [UIColor whiteColor];
NSMutableString *str = [[NSMutableString alloc] init];
for (NSUInteger i = 0; i < 100; i++) { [str appendFormat:@"%i ", i]; }
contentLabel.text = str;
[scroller addSubview:contentLabel];
scroller.contentSize = contentLabel.frame.size;
[cell addSubview:scroller];
}
// cell.textLabel.text = [NSString stringWithFormat:@"cell #%i", indexPath.row];
return cell;
}
我加入一些其他的UI組件到我的廈門國際銀行滾動型在運行時像按鈕等。代碼是如下
NSArray *colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor greenColor], [UIColor blueColor], nil];
for (int i = 0; i < colors.count; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIView *subview = [[UIView alloc] initWithFrame:frame];
subview.backgroundColor = [UIColor grayColor];
[self.scrollView addSubview:subview];
// add buttons
CGRect Frame= CGRectMake(frame.origin.x,frame.origin.y,200,50);
//set your x and y position whatever u want.
UIButton *Button = [UIButton buttonWithType:UIButtonTypeCustom];
Button.frame = Frame;
UIImage *Img = [UIImage imageNamed:@"second.png"];
[Button setBackgroundImage:Img forState:UIControlStateNormal];
[scrollView addSubview: Button];
// add text
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(frame.origin.x,frame.origin.y+60,200,50)];
label.textAlignment = UITextAlignmentCenter;
label.text = @"Here you write your text";
label.textColor = [UIColor blackColor];
[scrollView addSubview:label ];
[subview release];
請建議我用,我可以載入我的設計滾動視圖到的tableview細胞
感謝很多的修改!
如果存在一個更好的方法來實現我在做什麼,請建議! – 2013-04-07 06:50:33
OK同時,我也做了一些修改,並使用自定義的tableview細胞的方法和IM現在加載自定義單元格,但再次滾動視圖心不是可見的,我一直在使用IB我覺得這是加入initWithStyle同上面滾動視圖代碼和組件定製的tableview細胞更乾淨的方法,但沒有組件包括scrollview被加載到單元格中。 – 2013-04-07 19:09:40