iOS导航栏上的设置以及弹出框
来源:互联网 发布:照片编辑软件 编辑:程序博客网 时间:2024/05/22 12:48
1.导航栏上的一些常用属性设置
如果不喜欢系统提供给我们的样式 我们可以自己设置导航栏上面按钮的颜色、字体的颜色和字体大小
主要写在AppDelegate.m文件里面 导入ViewController.h文件
它的一些设置 代码如下:
#import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];
[self.windowmakeKeyAndVisible];
//UINavigationController:导航控制器
//初始化导航控制器同时给导航控制器一个根视图控制器根视图控制器是导航控制器上面的 第一个控制器
UINavigationController *navigationController = [[UINavigationControlleralloc]initWithRootViewController:[[ViewControlleralloc]init]];
self.window.rootViewController =navigationController;
//设置导航栏的背景颜色
[[UINavigationBarappearance]setBarTintColor:[UIColororangeColor]];
//设置导航栏上字体颜色和字体大小
[[UINavigationBarappearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColorwhiteColor],NSFontAttributeName:[UIFontboldSystemFontOfSize:20]}];
//设置导航栏上按钮颜色
[[UINavigationBarappearance]setTintColor:[UIColorgrayColor]];
return YES;
}
@end
可以看到效果图如下:
2.弹出框的使用 主要通过点击导航栏上面的左右按钮介绍了弹出框的两种不同风格以及可以在弹出框上面添加按钮
代码如下:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
self.view.backgroundColor = [UIColorwhiteColor];
self.title =@"首页";
[selfcreatBarButton];
}
#pragma mark---------设置导航栏上左右侧按钮
- (void)creatBarButton{
//创建导航栏上一个左侧按钮导航栏系统自带的按钮风格有24种风格在这里只列举了2种
UIBarButtonItem *left = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSearchtarget:selfaction:@selector(action:)];
self.navigationItem.leftBarButtonItem = left;
//创建导航栏上一个右侧按钮
UIBarButtonItem *right = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAddtarget:selfaction:@selector(action1:)];
self.navigationItem.rightBarButtonItem = right;
}
#pragma mark---------导航栏上左右侧按钮的触发事件的方法
- (void)action:(UIBarButtonItem *)sender{
//UIAlertController 弹出框控件 弹出框有2种样式
//UIAlertController初始化:
//+ (instancetype)alertControllerWithTitle:(nullable NSString *)title message:(nullable NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle
//创建弹出框选择弹出框样式 1.左右结构
UIAlertController *alertOfStyle = [UIAlertControlleralertControllerWithTitle:@"消息"message:@"加载成功"preferredStyle:UIAlertControllerStyleAlert];
//弹出框上面的按钮
UIAlertAction *okAlert = [UIAlertActionactionWithTitle:@"OK"style:UIAlertActionStyleDefaulthandler:nil];
UIAlertAction *cancelAlert = [UIAlertActionactionWithTitle:@"Cancel"style:UIAlertActionStyleCancelhandler:nil];
//把按钮添加到弹出框上面
[alertOfStyle addAction:okAlert];
[alertOfStyle addAction:cancelAlert];
[selfpresentViewController:alertOfStyleanimated:YEScompletion:nil];
}
- (void)action1:(UIBarButtonItem *)sender{
//创建弹出框选择弹出框样式2.上下结构
UIAlertController *sheetOfStyle = [UIAlertControlleralertControllerWithTitle:@"标题"message:@"选项样式的弹出框"preferredStyle:UIAlertControllerStyleActionSheet];
//弹出框上面的按钮
UIAlertAction *OK = [UIAlertActionactionWithTitle:@"确定"style:UIAlertActionStyleDefaulthandler:nil];
UIAlertAction *ALERT = [UIAlertActionactionWithTitle:@"警告"style:UIAlertActionStyleDestructivehandler:nil];
//把按钮添加到弹出框上面
[sheetOfStyle addAction:OK];
[sheetOfStyle addAction:ALERT];
[selfpresentViewController:sheetOfStyleanimated:YEScompletion:nil];
}
@end
可以看到弹出框的两个样式的效果如下:
- iOS导航栏上的设置以及弹出框
- ios学习(导航栏上两个简单的设置)
- iOS开发navigationBar导航条和navigationItem设置:基本搞定导航条上的文字和按钮以及各种跳转
- iOS导航栏的设置
- 【iOS开发-22】navigationBar导航条和navigationItem设置:基本搞定导航条上的文字和按钮以及各种跳转
- 设置导航栏上的返回按钮
- 导航栏上文字颜色的设置
- iOS设置导航栏颜色以及状态栏字体颜色
- ios 导航栏设置
- iOS 导航栏设置
- IOS ---设置导航栏
- iOS导航栏设置
- IOS 导航栏上的基本控件
- ios导航栏的背景图片设置
- iOS 设置导航栏的主题
- iOS--导航栏属性设置的介绍
- IOS NavigitionController导航栏的基本设置
- iOS导航栏的一些设置
- Android AutoCompleteTextView使用整理
- C语言的编译器及编译过程
- 《Android开发精要》读书笔记——Android应用模型
- 【函数式】Monads模式初探——Endofunctor
- UnicodeEncodeError: 'ascii' codec can't encode characters in position 6-10
- iOS导航栏上的设置以及弹出框
- 进程常驻
- linux work queue工作原理
- 使用ijl库Jpg转RGB
- unity shaderlab Blend操作
- iOS swift动画和特效专题
- 统计指定文件夹下的文件数量
- Jquery获取css中id和class样式的动作-#id和.class
- getParameter和getAttribute的区别