ios 导航栏透明
2016-05-27 01:00
471 查看
1. 创建透明图片(新建继承NSObject 的ImageUtil类)
+ (UIImage*)imageWithColor:(UIColor*)color size:(CGFloat)size
{
CGRect rect =CGRectMake(0.0f,0.0f,
size, size);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context =UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [colorCGColor]);
CGContextFillRect(context, rect);
UIImage *theImage =UIGraphicsGetImageFromCurrentImageContext(
4000
);
UIGraphicsEndImageContext();
return theImage;
}
2. 设置导航栏
UIImage *gradientImage44 = [ImageUtilimageWithColor:[UIColorcolorWithRed:1green:0blue:0alpha:0.5]size:1];
UIImage *gradientImage32 = [ImageUtilimageWithColor:[UIColorcolorWithRed:1green:0blue:0alpha:0.5]size:1];
[[UINavigationBarappearance]
setBackgroundImage:gradientImage44forBarMetrics:UIBarMetricsDefault];
[[UINavigationBarappearance]
setBackgroundImage:gradientImage32forBarMetrics:UIBarMetricsLandscapePhone];
[[UINavigationBarappearance]
setBarStyle:UIBarStyleDefault];
3.设置viewcontroller 放到viewDidLoad中
self.edgesForExtendedLayout =UIRectEdgeTop;
+ (UIImage*)imageWithColor:(UIColor*)color size:(CGFloat)size
{
CGRect rect =CGRectMake(0.0f,0.0f,
size, size);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context =UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [colorCGColor]);
CGContextFillRect(context, rect);
UIImage *theImage =UIGraphicsGetImageFromCurrentImageContext(
4000
);
UIGraphicsEndImageContext();
return theImage;
}
2. 设置导航栏
UIImage *gradientImage44 = [ImageUtilimageWithColor:[UIColorcolorWithRed:1green:0blue:0alpha:0.5]size:1];
UIImage *gradientImage32 = [ImageUtilimageWithColor:[UIColorcolorWithRed:1green:0blue:0alpha:0.5]size:1];
[[UINavigationBarappearance]
setBackgroundImage:gradientImage44forBarMetrics:UIBarMetricsDefault];
[[UINavigationBarappearance]
setBackgroundImage:gradientImage32forBarMetrics:UIBarMetricsLandscapePhone];
[[UINavigationBarappearance]
setBarStyle:UIBarStyleDefault];
3.设置viewcontroller 放到viewDidLoad中
self.edgesForExtendedLayout =UIRectEdgeTop;
相关文章推荐
- IOS学习之蓝牙4.0
- iOS9新特性-应用内搜索CoreSpotlight
- MVVM奇葩说
- [一句秒懂]ios 清除缓存
- iOS中的黑科技(一些方法或者功能的实现)
- 如何给iOS 分类添加 属性
- iOS ERROR: unable to get the receiver data from DB
- IOS博客项目搭建-16-发微博-点击button获取相册图片
- ios runtime基础应用
- 【iOS技术】Xcode+GitHub远程代码托管(GIT, SVN)
- iOS开发--遇到的友盟的几个坑
- iOS 多控制器之间的跳转和数据存储
- iOS 图片剪切
- 解决iOS上传图片后,图片方向错误的问题
- iOS开发中使用平率很高的宏定义
- ios时间戳和当前时间转换
- iOS 四舍五入
- iOS开发-进阶:沙盒操作与机制
- iOS开发:关键字说明
- 转发:招聘一个靠谱的 iOS