** 好记性不如烂笔头 记录一些自己在开发中经常用到的一些琐碎代码片段 会经常更新 .. **
1、目前iOS项目中要求导航栏的返回按钮只保留那个箭头,去掉后边的文字,在网上查了一些资料,最简单且没有副作用的方法就是
[UIBarButtonItem appearance]setBackButtonTitlePositionAdjustment:UIOffsetMake(0,-60)] for BarMetrics:UIBarMetricsDefault];
2、简单实现一个导航栏的下的提示视图 效果如下
- (void)showNewStatusesCount:(NSInteger)nums{
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont systemFontOfSize:12];
if (nums) {
label.text = [NSString stringWithFormat:@"新%ld条数据", count];
} else {
label.text = @"暂无新数据";
}
label.backgroundColor = [UIColor colorWithRed:0/255.0 green:174/255.0 blue:22/255.0 alpha:1.0];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.width = self.view.frame.size.width;
label.height = 35;
label.x = 0;
label.y = CGRectGetMaxY([self.navigationController navigationBar].frame) - label.frame.size.height;
[self.navigationController.view insertSubview:label belowSubview:self.navigationController.navigationBar];
[UIView animateWithDuration:.8f; animations:^{
label.transform = CGAffineTransformMakeTranslation(0, label.frame.size.height);
} completion:^(BOOL finished) { /
[UIView animateWithDuration:duration delay:.8f options:UIViewAnimationOptionCurveEaseInOut animations:^{
label.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
[label removeFromSuperview];
}];
}];
}
3、平时有用到更改label的行间距 使其排版看起来更美观