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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UIBarbuttonItem

發布時間:2023/12/18 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UIBarbuttonItem 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

APPDelegate:

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

? ? self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

? ? //創建主界面,導航欄的第一個頁面

? ? FirstViewController *fvc = [[FirstViewController alloc]init];

?? ?

? ? //創建一個導航欄控制器

? ? UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:fvc];

? ? nav.navigationBar.barTintColor = [UIColor redColor];

? ? self.window.rootViewController = nav;//設置根控制器

? ? [self.window makeKeyAndVisible];

? ? return YES;

}

?

//給導航欄添加左右按鈕

? ? UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]initWithTitle:@"cancel" style:UIBarButtonItemStyleDone target:nil action:nil];

? ? self.navigationItem.leftBarButtonItem = cancelButton;

? ? self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];

?? ?

? ? UIBarButtonItem *nextButton = [[UIBarButtonItem alloc]initWithTitle:@"next" style:UIBarButtonItemStyleDone target:self action:@selector(goToSecond)];

? ? self.navigationItem.rightBarButtonItem = nextButton ;

? ? self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];

?? ?

? ? UILabel *yLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];

? ? yLabel.backgroundColor = [UIColor yellowColor];

? ? yLabel.text = @"新浪";

? ? yLabel.font = [UIFont systemFontOfSize:22];

? ? yLabel.textColor = [UIColor redColor];

? ? yLabel.textAlignment = NSTextAlignmentCenter;

? ? self.navigationItem.titleView = yLabel;

-(void)goToSecond{

? ? //創建即將顯示的界面

? ? SecondViewController *svc = [[SecondViewController alloc]init];

? ? //使用導航欄控制器切換頁面

//? ? [self.navigationController presentViewController:svc animated:YES completion:nil];

? ? //push入棧 將當前的界面入棧,這個界面消失,將新的界面推送出來

? ? //pop 將當前的界面消失,從棧上最上面的界面(最后一個界面)出棧

? ? //設置默認提供的返回按鈕的標題

? ? UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:nil action:nil];

? ? self.navigationItem.backBarButtonItem = backItem; ?

? ? [self.navigationController showViewController:svc sender:self];

}

?

-(void)viewWillAppear:(BOOL)animated{

? ? [super viewWillAppear:animated];

? ? //顯示工具欄

? ? self.navigationController.toolbarHidden = NO;

? ? self.navigationController.toolbar.barTintColor = [UIColor greenColor];

? ? //默認工具欄高44,導航欄高44

? ? //可以隱藏導航欄

//? ? self.navigationController.navigationBarHidden = YES;

}

?SecondViewController類.m

-(void)viewDidLoad{

? ? [super viewDidLoad];

? ? UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

? ? [btn setTitle:@"back" forState:UIControlStateNormal];

? ? btn.frame = CGRectMake(100, 200, 120, 50);

? ? [btn addTarget:self action:@selector(goback) forControlEvents:UIControlEventTouchUpInside];

? ? btn.tintColor = [UIColor whiteColor];

? ? [self.view addSubview:btn];

}

-(void)goback{

?? ? //present 在現有的界面上蓋上一層,dismissViewController刪除

? ? //如果之前使用 的push 那么用pop

? ? [self.navigationController popViewControllerAnimated:YES];

? ? [self dismissViewControllerAnimated:YES completion:nil];

}

?

拓:navigationbar 上加多個button:

UIView *rightBarView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 60, 31)];UIButton *phonebutton = [UIButton buttonWithType:UIButtonTypeCustom];phonebutton.frame=CGRectMake(0, 5, 25, 25);[phonebutton setImage:[UIImage imageNamed:@"phone.png"] forState:UIControlStateNormal];[phonebutton addTarget:self action:@selector(phoneclick)forControlEvents:UIControlEventTouchDown];[rightBarView addSubview:phonebutton];UIButton *mapbutton = [UIButton buttonWithType:UIButtonTypeCustom];[mapbutton setFrame:CGRectMake(30, 5, 25, 25)];[mapbutton setImage:[UIImage imageNamed:@"c_address.png"] forState:UIControlStateNormal];[mapbutton addTarget:self action:@selector(mapclick)forControlEvents:UIControlEventTouchDown];[rightBarView addSubview:phonebutton];[rightBarView addSubview:mapbutton];rightBarView.backgroundColor=[UIColor clearColor];UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc]initWithCustomView:rightBarView];self.navigationItem.rightBarButtonItem = rightBtn;

?更簡便的方法:

轉載于:https://www.cnblogs.com/yangqinglong/p/5363708.html

總結

以上是生活随笔為你收集整理的UIBarbuttonItem的全部內容,希望文章能夠幫你解決所遇到的問題。

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