当前位置:网站首页>暑假第二周总结博客
暑假第二周总结博客
2022-08-01 18:03:00 【瓯海剑】
UINavigationController 背景颜色设计问题
- 升级到 Xcode 13 之前写的关于导航条 navigationBar 的颜色设置是直接调用 barTintColor 属性就可以实现。然而到了Xcode 13 颜色设置却失效了。
之前的代码:
// 设置不透明
self.navigationController.navigationBar.translucent = NO;
// 设置背景颜色
self.navigationController.navigationBar.tintColor = [UIColor redColor];
- 改之后
UINavigationBarAppearance* appearance = [[UINavigationBarAppearance alloc] init];
// 添加背景颜色
appearance.backgroundColor = [UIColor redColor];
appearance.shadowImage = [[UIImage alloc] init];
appearance.shadowColor = nil;
self.navigationController.navigationBar.standardAppearance = appearance;
self.navigationController.navigationBar.scrollEdgeAppearance = appearance;
按钮选中设置
创建按钮时,同时设置普通状态和选中状态的样式。
UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(100, 300, 200, 200);
button.selected = NO;
// 提取图片
UIImage* icon01 = [[UIImage imageNamed:@"btn01.jpeg"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage* icon02 = [[UIImage imageNamed:@"btn02.jpeg"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
// 设置普通状态图片
[button setImage:icon01 forState:UIControlStateNormal];
// 设置选中状态图片
[button setImage:icon02 forState:UIControlStateSelected];
// 添加事件
[button addTarget:self action:@selector(pressButton:) forControlEvents:UIControlEventTouchUpInside];
再点击事件中添加切换选中状态的代码。
- (void) pressButton:(UIButton*)button {
// 切换选中状态
button.selected = !button.selected;
}
UITabBarItem图片设置问题
当我用如下方法设置UITabBarItem图片时会遇到,图片无法显示问题(显示出来是一大块色块)。
UITabBarItem* TabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:[UIImage imageNamed:@"56.png"] selectedImage:[UIImage imageNamed:@"firstbutton_pressed.png"]];
navigationController.tabBarItem = TabBarItem;
示:
这是我们改变图片的渲染模式就可以解决:
UITabBarItem* TabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:[[UIImage imageNamed:@"56.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"firstbutton_pressed.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
navigationController.tabBarItem = TabBarItem;
改为 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal
。
边栏推荐
- Leetcode71. 简化路径
- 【Day_10 0428】密码强度等级
- ACID Characteristics and Implementation Methods of MySQL Relational Database Transactions
- COS 用户实践征文
- Leetcode72. 编辑距离
- SQL的ROUND函数用法及其实例
- Leetcode73. 矩阵置零
- B005 – 基于STC8的单片机智能路灯控制系统
- 成都理工大学&电子科技大学|用于强化学习的域自适应状态表示对齐
- 【报错】Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘concat‘)
猜你喜欢
C language theory--a solid foundation for the written test and interview
阿里云的域名和ip绑定
云原生全景图详解
DBPack SQL Tracing 功能及数据加密功能详解
JVM运行时数据区与JMM内存模型是什么
QT commonly used global macro definitions
Solve the problem that MySQL cannot insert Chinese data
B002 - Embedded Elderly Positioning Tracking Monitor
8月微软技术课程,欢迎参与
How to solve the dynamic binding of el-form-item prop attribute does not take effect
随机推荐
DBPack SQL Tracing 功能及数据加密功能详解
MySql 怎么查出符合条件的最新的数据行?
成都理工大学&电子科技大学|用于强化学习的域自适应状态表示对齐
tooltip control
Leetcode72. Edit Distance
QPalette调色板、框架色彩填充
B011 - 51-based multifunctional fingerprint smart lock
中信证券是国内十大券商吗?怎么开户安全?
三维空间中点的插值
How to solve the dynamic binding of el-form-item prop attribute does not take effect
关于MySql中explain结果filtered的理解
后台管理系统的权限思路
Leetcode75. Color Classification
B001 - 基于STM32的智能生态鱼缸
Solve the problem that MySQL cannot insert Chinese data
今年最火爆的词:商业分析,看这一篇就够了!
QT_QThread线程
Go iota关键字与枚举类型实现原理是什么
How to use the Golang coroutine scheduler scheduler
千万级乘客排队系统重构&压测方案总结篇