相关疑难解决方法(0)

在UITableViewHeaderFooterView中更改字体大小的麻烦

这是问题所在,

我将UITableViewHeaderFooterView子类化并想要更改字体大小:

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.textLabel.textColor = [UIColor colorWithWhite:0.8 alpha:1.0];
        //the font is not working
        self.textLabel.font = [UIFont systemFontOfSize:20];
        NSLog(@"aaa%@", self.textLabel.font);
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)

颜色的东西工作正常,但字体没有改变,所以我记录了dequeue:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UITableViewHeader *headerView = [self.tableView dequeueReusableHeaderFooterViewWithIdentifier:MWDrawerHeaderReuseIdentifier];
    headerView.textLabel.text = self.sectionTitles[@(section)];
    NSLog(@"bbb%@", headerView.textLabel.font);
    return headerView;
}
Run Code Online (Sandbox Code Playgroud)

字体仍然在这里,所以我登录didLayoutsubviews:

-(void)viewDidLayoutSubviews
{
    UITableViewHeaderFooterView *head = [self.tableView headerViewForSection:0];
    NSLog(@"ccc%@", head.textLabel.font);
}
Run Code Online (Sandbox Code Playgroud)

并且字体大小神奇地恢复到默认值!!! 但是我之间没有做任何事情,如果再次改变字体大小viewDidLayoutSubviews,字体就变得正确了.

它让我疯狂!!!

当子类化单元格时,我做同样的字体更改,它工作正常!所以有人能告诉我发生了什么事吗?谢谢!

这是日志:

2014-02-09 16:02:03.339 InternWell[33359:70b] aaa<UICTFont: 0x8da4290> …
Run Code Online (Sandbox Code Playgroud)

uitableview ios

17
推荐指数
2
解决办法
5078
查看次数

UITableView标题上的自动布局

我一直在寻找关于如何将自动布局添加到UITableView的明确答案.到目前为止,我的代码看起来像:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UINib *nib = [UINib nibWithNibName:@"HomeHeaderView" bundle:nil];
    UIView *headerView = (UIView *)[nib instantiateWithOwner:self options:nil][0];
    [headerView.layer setCornerRadius:6.0];
    [headerView setTranslatesAutoresizingMaskIntoConstraints:NO];

//    NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(headerView);
//    NSMutableArray *headerConstraints = [[NSMutableArray alloc] init];
//    [headerConstraints addObject:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[headerView]-|" options:0 metrics:nil views:viewsDictionary]];
//        [headerConstraints addObject:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[headerView]-|" options:0 metrics:nil views:viewsDictionary]];
//    [self.actionsTableView addConstraints:headerConstraints];
//    [self.view addSubview:headerView];
    tableView.tableHeaderView = headerView;
    [headerView layoutSubviews];

    NSLayoutConstraint *centerX = [NSLayoutConstraint constraintWithItem:headerView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
    NSLayoutConstraint *centerY = [NSLayoutConstraint constraintWithItem:headerView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view …
Run Code Online (Sandbox Code Playgroud)

ios autolayout

6
推荐指数
1
解决办法
1万
查看次数

UITableview 标头中的 UITapGesture

我试图在 swift 中使用可扩展的 tableview。所以我在tableview的标题中添加了Gesture,但它无法识别。请指导我。只需交叉检查我的编码。

我的编码如下:

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

        let vvv = tableView.headerViewForSection(section)

        let tap = UITapGestureRecognizer(target: self, action: Selector("handleTap:"))
        tap.delegate = self
        vvv?.addGestureRecognizer(tap)
        return vvv
    }


    func handleTap(gestureRecognizer: UITapGestureRecognizer)
    {
        if(gestureRecognizer.state == .Ended)
        {
            println("SECTION PRESSED") //NOT ENTERING TO THIS BLOCK
        }     
    }
Run Code Online (Sandbox Code Playgroud)

uitableview uigesturerecognizer swift ios8

3
推荐指数
1
解决办法
5872
查看次数

标签 统计

ios ×2

uitableview ×2

autolayout ×1

ios8 ×1

swift ×1

uigesturerecognizer ×1