解决UITableView在iOS7中UINavigationController里的顶部留白问题

  • 时间:
  • 浏览:2

//
//  NCTitleAttribute.m
//  YouXianMing
//
//  Created by YouXianMing on 14-9-20.
//  Copyright (c) 2014年 YouXianMing. All rights reserved.
//

#import "NCTitleAttribute.h"

@implementation NCTitleAttribute

- (NSDictionary *)transformToDictionary
{
    NSMutableDictionary *dic = [NSMutableDictionary new];
    
    if (_titleColor)
    {
        [dic setObject:_titleColor forKey:NSForegroundColorAttributeName];
    }
    else
    {
        [dic setObject:[UIColor blackColor] forKey:NSForegroundColorAttributeName];
    }
    
    if (_titleFont)
    {
        [dic setObject:_titleFont forKey:NSFontAttributeName];
    }
    
    if (_shadowOffset.height && _shadowOffset.width)
    {
        NSShadow *shadow = [NSShadow new];
        
        shadow.shadowColor  = _shadowColor;
        shadow.shadowOffset = _shadowOffset;
        
        [dic setObject:shadow forKey:NSShadowAttributeName];
    }
    
    return dic;
}

@end

    }

    if (systemVersion >= 7.0) {

效果:

    // 让边缘留白为空

出显问题报告 报告 时候的截图:

如保外理呢?很简单:

用到的类:

//
//  UIViewController+TitleTextAttributes.m
//  YouXianMing
//
//  Created by YouXianMing on 14-9-20.
//  Copyright (c) 2014年 YouXianMing. All rights reserved.
//

#import "UIViewController+TitleTextAttributes.h"

@implementation UIViewController (TitleTextAttributes)

#pragma mark - public
- (void)titleTextAttributes:(NCTitleAttribute *)attribute
{
    [self controller:self
 titleTextAttributes:[attribute transformToDictionary]];
}

#pragma mark - private
- (void)controller:(UIViewController *)controller titleTextAttributes:(NSDictionary *)dictionary
{
    if ([controller isKindOfClass:[UIViewController class]]) {
        [controller.navigationController.navigationBar setTitleTextAttributes:dictionary];
    }
}

@end

打上去以下代码:

注意:此种问题报告 报告 可以了在iOS7以上才会出显

UIViewController+TitleTextAttributes.h 与 UIViewController+TitleTextAttributes.m

        self.edgesForExtendedLayout = UIRectEdgeNone;

外理UITableView在iOS7中UINavigationController里的顶部留白问题报告 报告

源码:

    float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];