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

  • 时间:
  • 浏览:0
  • 来源:下载大发快三彩票代理—大发快三直播

效果:

换成以下代码:

UIViewController+TitleTextAttributes.h 与 UIViewController+TitleTextAttributes.m

    if (systemVersion >= 7.0) {

出理 UITableView在iOS7中UINavigationController里的顶部留白问题

跳出问题事先 的截图:

用到的类:

注意:此种问题能能不能 在iOS7以上才会跳出

    }

源码:

如可出理 呢?很简单:

//
//  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

        self.edgesForExtendedLayout = UIRectEdgeNone;

    // 让边缘留白为空

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

//
//  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