Bre*_*ent 15 iphone objective-c ios uirefreshcontrol
是否有可能使UIRefreshControl的背景随着控件的增长而增长?
我想为刷新控件设置彩色背景以匹配顶部单元格的背景颜色.更改tableview的背景颜色是不可接受的,因为底部的空单元格也会有颜色,但我需要它们保持白色.
Apple的邮件应用程序显示此行为.刷新控件的背景与灰色搜索栏匹配,但表视图底部的空单元格仍为正常白色.
这是一个示例屏幕截图,显示表格如何显示刷新控件被拉出时出现的丑陋白色:

Ale*_*lex 25
您必须使用bgColor创建一个视图,并在tableView中添加负y原点.
警告:
如果您不以这种方式插入此视图,则无法看到刷新控件:他将隐藏在您的视图下方.
- (void)viewDidLoad
{
[super viewDidLoad];
// Background Color
UIColor *bgRefreshColor = [UIColor grayColor];
// Creating refresh control
refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
[refreshControl setBackgroundColor:bgRefreshColor];
self.refreshControl = refreshControl;
// Creating view for extending background color
CGRect frame = self.tableView.bounds;
frame.origin.y = -frame.size.height;
UIView* bgView = [[UIView alloc] initWithFrame:frame];
bgView.backgroundColor = bgRefreshColor;
bgView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
// Adding the view below the refresh control
[self.tableView insertSubview:bgView atIndex:0]; // This has to be after self.refreshControl = refreshControl;
}
Run Code Online (Sandbox Code Playgroud)
Swift 版本更容易复制粘贴:)
斯威夫特 2
func viewDidLoad() {
super.viewDidLoad()
// Background Color
let backgroundColor = UIColor.grayColor()
// Creating refresh control
let refresh = UIRefreshControl()
refresh!.backgroundColor = backgroundColor
refresh!.addTarget(self, action: #selector(refresh), forControlEvents: UIControlEvents.ValueChanged)
refreshControl = refresh
// Creating view for extending background color
var frame = tableView.bounds
frame.origin.y = -frame.size.height
let backgroundView = UIView(frame: frame)
backgroundView.autoresizingMask = .FlexibleWidth
backgroundView.backgroundColor = backgroundColor
// Adding the view below the refresh control
tableView.insertSubview(backgroundView, atIndex: 0) // This has to be after refreshControl = refresh
}
Run Code Online (Sandbox Code Playgroud)
斯威夫特 3
func viewDidLoad() {
super.viewDidLoad()
// Background Color
let backgroundColor = .gray
// Creating refresh control
let refresh = UIRefreshControl()
refresh!.backgroundColor = backgroundColor
refresh!.addTarget(self, action: #selector(refresh), forControlEvents: .valueChanged)
refreshControl = refresh
// Creating view for extending background color
var frame = tableView.bounds
frame.origin.y = -frame.size.height
let backgroundView = UIView(frame: frame)
backgroundView.autoresizingMask = .flexibleWidth
backgroundView.backgroundColor = backgroundColor
// Adding the view below the refresh control
tableView.insertSubview(backgroundView, atIndex: 0) // This has to be after refreshControl = refresh
}
Run Code Online (Sandbox Code Playgroud)
现在可以通过简单地设置 UIRefreshControl 背景颜色属性来实现(Swift 5,iOS 13):
let ctrl = UIRefreshControl(frame: .zero)
ctrl.backgroundColor = UIColor.gray'
tableView.refreshControl = ctrl
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8256 次 |
| 最近记录: |