日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

ios 导航栏(自己定义和使用系统方式)

發布時間:2024/4/17 windows 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ios 导航栏(自己定义和使用系统方式) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

系統方式:

//1.設置導航欄背景圖片[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];self.navigationController.navigationBar.shadowImage = [[UIImage alloc]init];[[self navigationController] setNavigationBarHidden:NO animated:YES];self.navigationController.navigationBar.backgroundColor = [[UIColor alloc] initWithRed:248/255.0 green:248/255.0 blue:248/255.0 alpha:1.0];//2.導航面板左邊的取消按鈕UIButton* cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];if(cancelButton != nil){[cancelButton setTitle:POST_CANCEL_BUTTON forState: UIControlStateNormal];[cancelButton setFrame:CGRectMake(0, 0, WIDTH_SCREEN/5.0, 44)];[cancelButton setTitleColor:[[UIColor alloc] initWithRed:0 green:158/255.0 blue:150/255.0 alpha:1.0]forState:UIControlStateNormal];cancelButton.titleLabel.font = [UIFont systemFontOfSize: 16.0];cancelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;[cancelButton addTarget:self action:@selector(cancelButtonEventTouchUpInside)forControlEvents :UIControlEventTouchUpInside];UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:cancelButton];if(leftItem != nil){self.navigationItem.leftBarButtonItem = leftItem;}}//3.導航面板右邊的公布按鈕UIButton* postButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];if (postButton != nil){[postButton setFrame:CGRectMake(0, 0, WIDTH_SCREEN/5.0, 44)];[postButton setTitle:@"公布" forState:UIControlStateNormal];[postButton setTitleColor:[[UIColor alloc] initWithRed:0 green:158/255.0 blue:150/255.0 alpha:1.0]forState:UIControlStateNormal];postButton.titleLabel.font = [UIFont systemFontOfSize: 16.0];postButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;[postButton addTarget:self action:@selector(postButtonEventTouchUpInside)forControlEvents :UIControlEventTouchUpInside];UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:postButton];if(rightItem != nil){self.navigationItem.rightBarButtonItem = rightItem;}}//4.導航面板中部文字UILabel* navigationLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 44)];if (navigationLabel != nil){[navigationLabel setTextColor:[UIColor blackColor]];navigationLabel.text = POST_NAVIGATION_TITLE;[navigationLabel setTextAlignment:NSTextAlignmentCenter];navigationLabel.font = [UIFont systemFontOfSize:18.0];self.navigationItem.titleView = navigationLabel;}//5.導航以下的一條切割線UIView* line = [[UIView alloc]initWithFrame:CGRectMake(0, 20 + 44,WIDTH_SCREEN, 1)];if (line != nil){line.backgroundColor = [[UIColor alloc] initWithRed:221/255.0 green:221/255.0 blue:221/255.0 alpha:1.0];[self.view addSubview:line];}
自己定義:

//1.創建導航欄視圖UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH_SCREEN, 65)];if (navView != nil)//當導航視圖沒有載入成功的時候推出該方法{//1.為導航視圖設置背景navView.backgroundColor = [UIColor colorWithRed:248 / 255.0 green:248 / 255.0 blue:248 / 255.0 alpha:1];[[self navigationController] setNavigationBarHidden:YES animated:YES];//2.導航面板左邊的取消按鈕UIButton* leftButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];if (leftButton != nil){leftButton.frame = CGRectMake(15, 20, 65, 44);[leftButton setTitle:POST_CANCEL_BUTTON forState: UIControlStateNormal];[leftButton setTitleColor:[[UIColor alloc] initWithRed:0 green:158/255.0 blue:150/255.0 alpha:1.0]forState:UIControlStateNormal];leftButton.titleLabel.font = [UIFont systemFontOfSize: 16.0];leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;[leftButton addTarget:self action:@selector(cancelButtonEventTouchUpInside)forControlEvents :UIControlEventTouchUpInside];[navView addSubview:leftButton];}//3.導航面板右邊的公布按鈕UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];if (rightButton != nil){[rightButton setFrame:CGRectMake(WIDTH_SCREEN - 80, 20, 65, 44)];[rightButton setTitle:@"公布" forState:UIControlStateNormal];[rightButton setTitleColor:[[UIColor alloc] initWithRed:0 green:158/255.0 blue:150/255.0 alpha:1.0]forState:UIControlStateNormal];rightButton.titleLabel.font = [UIFont systemFontOfSize: 16.0];rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;[rightButton addTarget:self action:@selector(postButtonEventTouchUpInside)forControlEvents :UIControlEventTouchUpInside];[navView addSubview:rightButton];}//4.導航面板中部文字UILabel* navTitle = [[UILabel alloc] initWithFrame:CGRectMake(80, 20, WIDTH_SCREEN - 80 - 80, 44)];if (navTitle != nil){[navTitle setTextColor:[UIColor blackColor]];navTitle.text = POST_NAVIGATION_TITLE;[navTitle setTextAlignment:NSTextAlignmentCenter];navTitle.font = [UIFont systemFontOfSize:18.0];[navView addSubview:navTitle];}//5.在導航視圖底加入切割線UIView *navDividingLine = [[UIView alloc] init];if (navDividingLine != nil){navDividingLine.frame = CGRectMake(0, 20 + 44, WIDTH_SCREEN, 1);navDividingLine.backgroundColor = [UIColor colorWithRed:221 / 255.0 green:221 / 255.0 blue:221 / 255.0 alpha:1];[navView addSubview:navDividingLine];}//6.往view添加導航欄[self.view addSubview:navView];}

總結

以上是生活随笔為你收集整理的ios 导航栏(自己定义和使用系统方式)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。