零碎知识点01
1.需要设置Button的image和backgroundImage,建议先把按钮类型改为custom,才能保证设置成功.如果设置为custom,那么button的尺寸和内容都要自己实现。
例:
UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[backBtn setImage:[UIImage imageNamed:@"navigationbar_back"] forState:UIControlStateNormal];
[backBtn setImage:[UIImage imageNamed:@"navigationbar_back_highlighted"] forState:UIControlStateHighlighted];
//设置button的尺寸
backBtn.frame = CGRectMake(0, 0, backBtn.currentImage.size.width, backBtn.currentImage.size.height);
2.属性名不能以new开头
例:@property (weak, nonatomic) IBOutlet UIImageView *newImageView; 会报错!
3.只有在init开头的构造方法中,才允许对self赋值
- (instancetype)initWithName:(NSString *)name
{
if (self = [super init]) {
}
return self;
}
4.设置图片和文字样式
// RGB颜色
#define HWColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
(r) --> 用() 如:(100+23)
// 随机色
#define HWRandomColor HWColor(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))
// 设置子控制器的图片
childVc.tabBarItem.image = [UIImage imageNamed:image];
childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//设置文字的样式
NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
textAttrs[NSForegroundColorAttributeName] = HWColor(123, 123, 123);
NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
selectTextAttrs[NSForegroundColorAttributeName] = [UIColor orangeColor];
[childVc.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
[childVc.tabBarItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];
如:微博tabBarItem的图片和文字在选中时为orangeColor
5.设置子控制器的文字
childVc.title = title; // 同时设置tabbar和navigationBar的文字
// childVc.tabBarItem.title = title; // 设置tabbar的文字
// childVc.navigationItem.title = title; // 设置navigationBar的文字