iOS 设置tabBar点击后Item的背景颜色.
2016-01-12 15:39
746 查看
正常在用tabBarController的时候背景色的设置可以是
[_tabbarViewController.tabBarsetBackgroundImage:[UIImageimageWithColor:UIColorFromRGB(0xf5f5f5)]];
但是当你点击某个Item 想让Item的背景色发生变化.可以参考下面这段代码.
_tabbarViewController.tabBar.selectionIndicatorImage
= [UIImageimageWithColor:UIColorFromRGB(0xffffff)size:CGSizeMake(SCREEN_WIDTH
/4,PHONE_CUSTOM_TABBAR_HEIGHT)];
上面那两个类方法并不是系统的,是我写到了UIImage的类目里 内部实现如下。
+ (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect =CGRectMake(0.0f,0.0f,
1.0f,1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context =UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [colorCGColor]);
CGContextFillRect(context, rect);
UIImage *theImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size {
if (!color || size.width <=0 || size.height <=0)
return nil;
CGRect rect =CGRectMake(0.0f,0.0f, size.width, size.height);
UIGraphicsBeginImageContextWithOptions(rect.size,NO,
0);
CGContextRef context =UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, rect);
UIImage *image =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
[_tabbarViewController.tabBarsetBackgroundImage:[UIImageimageWithColor:UIColorFromRGB(0xf5f5f5)]];
但是当你点击某个Item 想让Item的背景色发生变化.可以参考下面这段代码.
_tabbarViewController.tabBar.selectionIndicatorImage
= [UIImageimageWithColor:UIColorFromRGB(0xffffff)size:CGSizeMake(SCREEN_WIDTH
/4,PHONE_CUSTOM_TABBAR_HEIGHT)];
上面那两个类方法并不是系统的,是我写到了UIImage的类目里 内部实现如下。
+ (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect =CGRectMake(0.0f,0.0f,
1.0f,1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context =UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [colorCGColor]);
CGContextFillRect(context, rect);
UIImage *theImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size {
if (!color || size.width <=0 || size.height <=0)
return nil;
CGRect rect =CGRectMake(0.0f,0.0f, size.width, size.height);
UIGraphicsBeginImageContextWithOptions(rect.size,NO,
0);
CGContextRef context =UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, rect);
UIImage *image =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
相关文章推荐
- ios pan手势
- iOS 开发学习35 本地化
- 在IOS开发中,属性名为id的处理方法
- iOS 一些常用的手机号、密码、数字等判断
- iOS事件传递,响应者链条
- iOS autoLayout Masonry框架
- iOS 获取当前时间和时间戳
- iOS fontWithName字体设置
- iOS 工程中调用设备拍照等官方功能时操作语言为英文的解决方案
- IOS代理模式(监听器模式)
- ios视图frame与bounds的区别
- ios 轻扫手势
- ios 旋转手势
- ios 缩放手势
- [iOS]FFmpeg框架在iOS平台上的编译和使用
- ios开发下的点透处理
- IOS开发之关于cocoaPods 第三方的使用
- iOS开发插件集
- iOS--错误集锦--Your session has expired. Please log in.
- Cacti和Nagios整合