BufferedImage不能引用什么意思

当前位置:
& Swift - 修改tableView分组(section)头部、尾部的字体颜色和大小
Swift - 修改tableView分组(section)头部、尾部的字体颜色和大小
发布:hangge
阅读:1237
我原来写过一篇关于表格(tableView)分组(section)的文章:。默认情况下,每个 section 头、尾的样式如下:
如果想要改变分组头尾里文字的颜色、大小样式。通常有两种方法。
1,通过UIAppearance协议统一修改(UIAppearance Protocol)
使用这种方式会将 App 中所有的 tableView 的分组头部、尾部文本标签样式进行统一修改。比如下面代码,我们将标签颜色改成黑色斜体,并加大字号。
override func viewDidLoad() {
super.viewDidLoad()
//设置分区头尾的文字颜色:黑色
UILabel.appearance(whenContainedInInstancesOf: [UITableViewHeaderFooterView.self])
.textColor = UIColor.black
//设置分区头尾的文字样式:15号斜体
UILabel.appearance(whenContainedInInstancesOf: [UITableViewHeaderFooterView.self])
.font = UIFont.italicSystemFont(ofSize: 15)
效果图如下:
2,使用viewForHeaderInSection或viewForFooterInSection单独修改
通过 viewForHeaderInSection 和 viewForFooterInSection 方法可以单独为每一个表格,甚至每个分组自定义不同的头尾视图,自然可以实现文字的样式自定义。
比如下面代码将分组头部改成白色文字,黑色背景。
//返回分区头部视图
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -& UIView? {
let headerView = UIView()
headerView.backgroundColor = UIColor.black
let titleLabel = UILabel()
titleLabel.text = self.adHeaders?[section]
titleLabel.textColor = UIColor.white
titleLabel.sizeToFit()
titleLabel.center = CGPoint(x: self.view.frame.width/2, y: 20)
headerView.addSubview(titleLabel)
return headerView
//返回分区头部高度
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -& CGFloat {
效果图如下:14:45 提问
有没有什么简单的方法改变tableView右边索引的背景和字母的颜色?
如图, 有没有什么简单的方法改变tableView右边索引的背景颜色,或者弄成透明色,以及怎么修改检索字母的颜色
按赞数排序
sectionIndexBackgroundColor
sectionIndexColor查看:6893|回复:2
助理工程师
我想要让header居中在tableView中,请问该怎么做呢?
我有两个问题,首先,我不知道争取的高度,然后,UILabel好像不是默认的header,字体,字体大小等等。
请问有什么方法可以居中的吗? - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger) section
& & //section text as a label
& & UILabel *lbl = [[UILabel alloc] init];
& & lbl.textAlignment = UITextAlignmentC&&
& & lbl.text = @&Header&;
& & [lbl setBackgroundColor:[UIColor clearColor]];&&
助理工程师
这个你要设置table的头的位置吧,设置一下它的frame。
补充内容 ( 13:15):
设置一下label的frame值。
助理工程师
- (UIView *)tableView:(UITableView *)tableView
& && && && && && && && &viewForHeaderInSection:(NSInteger)section {
& & return 15;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,320,15)];
label.textAlignment = UITextAlignmentCenter
label.text = @&Text Should Be Centered&;- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {&&& view.tintColor = [UIColor clearColor];}
阅读(...) 评论()

我要回帖

更多关于 引用 的文章

 

随机推荐