【问题标题】:iOS customize scrollbar in UITableViewiOS 在 UITableView 中自定义滚动条
【发布时间】:2012-07-20 06:58:46
【问题描述】:

在 iPhone 中,我将使用图像自定义 UITableView 的滚动条。 但是我没有找到正确的方法。 请帮我。 提前致谢。

【问题讨论】:

  • 您的问题不清楚,请在您的问题中添加更多详细信息..

标签: iphone ios uitableview scrollbar customization


【解决方案1】:

首先,您必须在 Interface Builder 中取消选中 showVerticalIndicatir 和 showHorizo​​ntallIndicatir。

然后在 ViewDidLoad 方法中添加:

    [super viewDidLoad];
    self.scrollViewBarImgView = [[UIImageView alloc] init];
    UIImage *imgBar = [UIImage imageNamed:@"scroller.png"];
    [self.scrollViewBarImgView setImage:imgBar];
    CGRect frame = scrollViewBarImgView.frame;
    frame.size.width = 8;
    frame.size.height = 60;
    frame.origin.x = 312;
    frame.origin.y = 0;
    [self.scrollViewBarImgView setFrame:frame];

[self.tableView addSubview:scrollViewBarImgView];

然后在 - (void)scrollViewDidScroll 方法中:

CGPoint offset = scrollView.contentOffset;
CGRect frame = self.scrollViewBarImgView.frame
float fact = (cellHeight*numberOfRow+ indicatorBarHeight) / tableViewHeight;
frame.origin.y = offset.y + (offset.y/fact);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.1];
[self.scrollViewBarImgView setFrame:frame];
[UIView commitAnimations];

【讨论】:

  • 我已经使用了这个解决方案并进行了一些修改。例如,动画部分不是必需的;事实上,它会在滚动中产生一些滞后。谢谢@SOUA Hamza。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-02
  • 2011-11-13
相关资源
最近更新 更多