iOS 导航栏的一些使用属性记录(备忘)

来源:互联网 发布:淘宝口红代购ysl 编辑:程序博客网 时间:2024/05/01 20:58

1, 代码块---copy

2,   代理---weak(strong不能被dealloc释放)    dealloc 里面释放 delegate,block,timer,除移通知

3.   button可以绑定状态来做很多操作(normal,dsiaable)

////////////////////////////////////////////////////////////////////////////////////////////////////////

#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]


#define CAREMAINCOLOR  RGBCOLOR(86,206,186)


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    

    //设置导航颜色

    [[UINavigationBarappearance]setBarTintColor:CAREMAINCOLOR];

    //导航的“<Back”字体颜色(大多数都是重写)

    [[UINavigationBarappearance]setTintColor:[UIColorwhiteColor]];

    //设置导航白色字体

    [[UINavigationBarappearance]setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:

                                                          [UIColorcolorWithRed:245.0/255.0green:245.0/255.0blue:245.0/255.0alpha:1.0],NSForegroundColorAttributeName,

                                                         nil,NSShadowAttributeName,

                                                          [UIFontfontWithName:@"HelveticaNeue-CondensedBlack"size:21.0],NSFontAttributeName,nil]];;

    UINavigationController *navController = [[UINavigationControlleralloc]initWithRootViewController:[[LPViewControlleralloc]init]];

    navController.navigationBar.translucent =NO;

    //隐藏导航

    //[navController setNavigationBarHidden:YES animated:YES];

   self.window.rootViewController = navController;


    return YES;

}


注意:

 iOS7以上系统,self.navigationController.navigationBar.translucent默认为YES,self.view.frame.origin.y从0开始(屏幕最上部)。
     此时若是添加代码self.edgesForExtendedLayout = UIRectEdgeNone(iOS7.0以后方法);self.view.frame.origin.y会下移64像素至navBar下方开始。


1.当   navController.navigationBar.translucent =YES;


2.控制器里面

if ([UIDevicecurrentDevice].systemVersion.floatValue>=7.0) {

        self.edgesForExtendedLayout =UIRectEdgeNone;

    }




解决:(在控制器里面+)  

1.方法一

if ([UIDevicecurrentDevice].systemVersion.floatValue>=7.0) {

        self.edgesForExtendedLayout =UIRectEdgeNone;

    }

2..方法二

 navController.navigationBar.translucent =NO;

一般我对导航的重写(base controller)


////  MSCareCustomViewController.m//  Care////  Created by linpeng on 14-7-11.//  Copyright (c) 2014年 moshi. All rights reserved.//#import "MSCareCustomViewController.h"@interface MSCareCustomViewController ()@end@implementation MSCareCustomViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];    if (self) {        // Custom initialization    }    return self;}- (void)viewDidLoad{    [super viewDidLoad];    [self.view setBackgroundColor:[UIColor whiteColor]];        if (iOS_VERSION_NOT_LESS_THAN_7) {        self.automaticallyAdjustsScrollViewInsets = NO;    }    if (self.navigationItem.leftBarButtonItem == nil) {        //判别导航的第一个控制器不需要“返回”按钮        if (self.navigationController.viewControllers.count > 1) {            NSString *backTitle = @"返回";            [self createAndSetCustomBackButtonWithTitle:backTitle];        }    }}-(UIButton *)createAndSetCustomBackButtonWithTitle:(NSString *)title{    UIButton *backButton = [self createCustomBackButtonWithTitle:title];    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];    [backButton addTarget:self action:@selector(customBackButtonOnclicked:) forControlEvents:UIControlEventTouchUpInside];        self.navigationItem.leftBarButtonItem = backItem;    return backButton;}-(UIButton *)createCustomBackButtonWithTitle:(NSString *)title{    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];    [backButton setImage:[UIImage imageNamed:@"ms_care_login_navigationbar_back"] forState:UIControlStateNormal];        [backButton setTitle:[NSString stringWithFormat:@" %@",title] forState:UIControlStateNormal];    [backButton setTitleColor:[UIColor greenColor] forState:UIControlStateSelected];    [backButton.titleLabel setFont:[UIFont systemFontOfSize:15]];    backButton.frame = CGRectMake(0, 0, 100, 30);    backButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;        return backButton;}-(void)customBackButtonOnclicked:(id)sender{    if (self.navigationController) {        [self.navigationController popViewControllerAnimated:YES];    }}-(void)removeBackButton{    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:self action:nil];    self.navigationItem.leftBarButtonItem = backItem;}- (void)didReceiveMemoryWarning{    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}/* #pragma mark - Navigation  // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */@end





0 0
原创粉丝点击