#pragma mark --導航欄 或自定義view /* * 建立導航欄 ! PS::::navbar只能設置背景圖片,不能設置背景顏色,否則會形成有一層遮罩層。建議純色繪製圖片代替背景 */ -(void)createNavBar{ //建立一個導航欄 UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH,64)]; // navBar.backgroundColor = [UIColor clearColor]; UIImage *image = [UIImage imageWithColor:[UIColor orangeColor] size:CGSizeMake(640, 90)]; [navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; //建立一個導航欄集合 UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:nil]; UIButton* leftBut = [UIButton buttonWithType:UIButtonTypeCustom]; leftBut.frame = CGRectMake(0, 0, 14, 23); [leftBut setBackgroundImage:[UIImage imageNamed:@"NavBackBtn_Nor.png"] forState:UIControlStateNormal]; [leftBut addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside]; //建立一個左邊按鈕 UIBarButtonItem *leftButton = [[UIBarButtonItem alloc]initWithCustomView:leftBut]; //設置導航欄的內容 [navItem setTitle:@"忘記密碼"]; //設置 UINavigationBar的標題字體顏色和大小 [navBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor, [UIFont systemFontOfSize:20.0], UITextAttributeFont, [NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset,nil]]; //把導航欄集合添加到導航欄中,設置動畫關閉 [navBar pushNavigationItem:navItem animated:NO]; //把左右兩個按鈕添加到導航欄集合中去 [navItem setLeftBarButtonItem:leftButton]; //將標題欄中的內容所有添加到主視圖當中 [self.view addSubview:navBar]; }