iphone - iOS自定义UITableView中的滚动条

标签 iphone ios uitableview scrollbar customization

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

最佳答案

首先,您必须取消选中 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];

关于iphone - iOS自定义UITableView中的滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11574352/

相关文章:

iphone - View 之间的持久数据

ios - 在 iOS 7/iOS 8 中设置 UILabel 文本样式的最简单方法

objective-c - 通过 CocoaPods 在 github 上使用 Restkit 的分支?

ios - 容器 View 页面 Controller 被裁剪而不是调整大小

ios - 如何在 iOS 中创建类似于 yelp 的复杂 ScrollView ?

ios - Swift-Access UILabels 在 UITableView 的动态单元格中

iphone - 在 iTunes Store 上上传构建版本时出现警告

iphone - 以编程方式获取结合 OpenGL 和 UIKit 元素的屏幕截图

iphone - 从 View 中移除 tabBar

ios - TableView 单元格中的 UILabel 和 UISwitch