iOS學(xué)習(xí)(UI)知識點整理
1 //初始化導(dǎo)航欄 2 FirstViewController *firstVC = [[FirstViewController alloc] init]; 3 UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:firstVC]; 4 self.window.rootViewController = nav; 5 6 //appearance一定要在初始化之前使用 7 //修改默認的UINavigationBar的導(dǎo)航條背景顏色, 8 [[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]]; 9 10 //修改默認的導(dǎo)航欄文字即圖標顏色11 [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];12 13 //設(shè)置導(dǎo)航欄背景圖片14 [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"icon"] forBarMetrics:UIBarMetricsDefault];
1 [self.navigationController setNavigationBarHidden:YES];1 self.title = @“First View”;2 //注意:在一處做此設(shè)置后,后面的視圖控制器如未作設(shè)置也會使用此標題
1 UIView *navBarView = [[UIView alloc] init]; 2 navBarView.frame = CGRectMake(0, 0, 100, 30); 3 navBarView.backgroundColor = [UIColor clearColor]; 4 navBarView.layer.cornerRadius = 8.0f; 5 navBarView.clipsToBounds = YES; 6 7 UIButton *btn1 = [[UIButton alloc] init]; 8 btn1.frame = CGRectMake(0, 0, 50, 30); 9 btn1.backgroundColor = [UIColor blueColor];10 [btn1 setTitle:@"消息" forState:UIControlStateNormal];11 [btn1 addTarget:self action:@selector(btn1Tapped:) forControlEvents:UIControlEventTouchUpInside];12 btn1.tag = 1000;13 [navBarView addSubview:btn1];14 15 UIButton *btn2 = [[UIButton alloc] init];16 btn2.frame = CGRectMake(50, 0, 50, 30);17 btn2.backgroundColor = [UIColor blueColor];18 [btn2 setTitle:@"電話" forState:UIControlStateNormal];19 [btn2 addTarget:self action:@selector(btn1Tapped:) forControlEvents:UIControlEventTouchUpInside];20 btn2.tag = 1001;21 [navBarView addSubview:btn2];22 23 //在導(dǎo)航欄中的中間位置加入我們自定義的view,24 //程序會把我們設(shè)置的view自動居中25 self.navigationItem.titleView = navBarView;
/*
* UIBarButtonSystemItemDone 按鈕樣式為文字Done、
* UIBarButtonSystemItemAdd 按鈕樣式為圖片的加號
*UIBarButtonSystemItemCamera 按鈕樣式是圖片的照相機
*UIBarButtonSystemItemFixedSpace 是一個占位符 ,可以設(shè)置width
*UIBarButtonSystemItemFlexibleSpace 是一個占位符,固定寬度,導(dǎo)航欄上單獨一個按鈕
*/
例如:
1 //系統(tǒng)自帶照相機按鈕2 UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
target:self action:@selector(barButtonTapped:)];3 4 //占位符按鈕5 UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:self action:@selector(barButtonTapped:)];
1 self.navigationItem.rightBarButtonItem = button1;
1 self.navigationItem.rightBarButtonItems = @[button2, button1];
1 self.edgesForExtendedLayout = UIRectEdgeNone;
1 UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain
target:self action:@selector(back)];
1 UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"st_logout"]
style:UIBarButtonItemStylePlain target:self action:@selector(back)];2 self.navigationItem.leftBarButtonItem = barButtonItem;
1 [self.navigationController setToolbarHidden:NO];
1 - (void)viewDidLoad { 2 [super viewDidLoad]; 3 self.view.backgroundColor=[UIColor whiteColor]; 4 5 firstView=[[UIView alloc]init]; 6 firstView.frame=CGRectMake(0, 20, 50, 50); 7 firstView.backgroundColor=[UIColor blackColor]; 8 [self.view addSubview:firstView]; 9 for (int i=0; i<4; i++) { 10 UIButton *btn=[[UIButton alloc]init]; 11 btn.frame=CGRectMake(20,50, CGRectGetWidth(self.view.frame), 30); 12 } 13 [self moveFirstViewToRight];14 }15 16 -(void)moveFirstViewToRight{ 17 //UIview 動畫18 [UIView animateWithDuration:3.f animations:^{19 firstView.frame=CGRectMake(self.view.frame.size.width-firstView.frame.size.width, 20, 50, 50);20 }];21 }
新聞熱點
疑難解答