为UINavigationBar添加自定义背景

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
    //颜色填充
//  UIColor *color = [UIColor redColor];
//  CGContextRef context = UIGraphicsGetCurrentContext();
//  CGContextSetFillColor(context, CGColorGetComponents( [color CGColor]));
//  CGContextFillRect(context, rect);
//  self.tintColor = color;
    //图片填充
    UIColor *color = [UIColor colorWithRed:46.0f/255.0f green:87.0f/255.0f blue:29.0f/255.0f alpha:1.0f];
    UIImage *img    = [UIImage imageNamed: @"bg.png"];
    [img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    self.tintColor = color;
}
@end

图示:

posted @   王喆(nasa)  阅读(4093)  评论(1编辑  收藏  举报
编辑推荐:
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 我与微信审核的“相爱相杀”看个人小程序副业
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· spring官宣接入deepseek,真的太香了~
点击右上角即可分享
微信分享提示