Nur*_* II 3 xcode objective-c uitableview ios
我想在表格视图部分添加分隔线.目前,标题部分视图的代码将是:
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
// recast your view as a UITableViewHeaderFooterView
UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
header.backgroundView.backgroundColor = [UIColor clearColor];
header.textLabel.textColor = [UIColor blackColor];
[header.textLabel setFont:[UIFont fontWithName:@"Rubik-Regular" size:15.0]];
}
Run Code Online (Sandbox Code Playgroud)
rsh*_*kar 10
斯威夫特4
override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let footerView = UIView()
let separatorView = UIView(frame: CGRect(x: tableView.separatorInset.left, y: footerView.frame.height, width: tableView.frame.width - tableView.separatorInset.right - tableView.separatorInset.left, height: 1))
separatorView.backgroundColor = UIColor.separatorColor
footerView.addSubview(separatorView)
return footerView
}
extension UIColor {
class var separatorColor: UIColor {
return UIColor(red: 244.0/255.0, green: 244.0/255.0, blue: 244.0/255.0, alpha: 1.0)
}
}
Run Code Online (Sandbox Code Playgroud)
如果你有
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)
最好让它在那里:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
// recast your view as a UITableViewHeaderFooterView
UITableViewHeaderFooterView *header = // make header here
header.backgroundView.backgroundColor = [UIColor clearColor];
header.textLabel.textColor = [UIColor blackColor];
[header.textLabel setFont:[UIFont fontWithName:@"Rubik-Regular" size:15.0]];
// make a view with height = 1 attached to header bottom
UIView *separator = [[UIView alloc] initWithFrame:CGRectMake(0, header.frame.size.height, header.frame.size.width, 1)];
[separator setBackgroundColor:[UIColor yellowColor]];
[header addSubview:separator];
return header;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8096 次 |
| 最近记录: |